0

i have this weird issue, my flask app works perfectly fine as long as i am opening the page from Mac machine.

but when i open the page from Windows machine (Chrome/IE) when i click the bottom to return the output, it just shows me a blank page. i cant understand why that's happening and i don't know how to google it :)

with that being said, i have moved the entire app to a windows server but again i cant see the output page on a windows machine whereas i see it perfectly fine from Mac Machine. any tip will be much appreciate it!!!

here's a sample code that i have in the app

@app.route('/vxlan_config', methods=["GET", "POST"])
def vxlan_config():
    vxlan_config_file = open("/Users/ahmad/ShcConfigs/vxlan_config.txt", "w")
    if request.method == "POST":
        vlanid = request.form["vlanid"]
        description = request.form["description"]
        vrf = request.form["vrf"]
        ip = request.form["ip"]
        mask = request.form["mask"]
        vxlan_conf = SHCDCConfig(vlanid, description, vrf, ip, mask)
        vxlan_config_file.write(vxlan_conf.vxlan_config())
        return send_file("/Users/ahmad/ShcConfigs/vxlan_config.txt",
                         attachment_filename='vxlan_config.txt')
    return render_template('vxlan_config.html')
Ahmad_R
  • 62
  • 1
  • 8

1 Answers1

1

"/Users/ahmad/ShcConfigs/vxlan_config.txt" is a path to a file on your Mac!

Here is python code to help you make a platform-agnostic path to your file:

https://docs.python.org/3/library/pathlib.html

This will help find the available directories to place your file:

def vxlan_config():
    import os
    print( os.getcwd() )
    print( os.path.dirname(os.path.abspath(__file__)) )
    print( os.path.dirname(os.path.dirname(os.path.abspath(__file__))) )
    print( os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) )

    print( os.path.join(os.path.dirname(__file__), 'vxlan_config.txt') )

I put all these here because I do not know your directory tree. Hopefully, you will recognize it now.

GAEfan
  • 11,244
  • 2
  • 17
  • 33
  • What should I use so windows users can see the page too? – Ahmad_R Aug 07 '20 at 21:56
  • i have moved the entire app to a windows server and changed those paths to windows, but still when i access it from windows machine its not functional where as it works perfectly fine from Mac machine – Ahmad_R Aug 07 '20 at 22:07
  • @user2251348 See this answer re: windows paths: https://stackoverflow.com/a/2953843/2052575 – v25 Aug 07 '20 at 22:10
  • this code is supposed to send the file whereever it is, 'return send_file("/Users/ahmad/ShcConfigs/vxlan_config.txt", attachment_filename='vxlan_config.txt')' – Ahmad_R Aug 07 '20 at 22:33
  • i have the same issue in windows server too, yes i have changed the path to windows path format, but i still cant get it to open – Ahmad_R Aug 07 '20 at 22:35
  • GAEfan, thanks so much for sending those commands. but i have changed the path and still the same problem. would you mind to get in touch via email so i can show you exactly where the issue is? – Ahmad_R Aug 07 '20 at 23:28
  • Update your question to show the paths, and where you will store the file. – GAEfan Aug 07 '20 at 23:37