Forums

document write working on local server but not in pythonanywhere

document write working on local server but not in pythonanywhere

with open(f'templates/{Randomint}.html', 'w') as f:

.

FileNotFoundError: [Errno 2] No such file or directory: 'templates/3154673393.html'

It's a document that dosen't exist but it generates from a python string with

with open(f'templates/{Randomint}.html', 'w') as f:
                   f.write(html_string)
webbrowser.open_new_tab(f"http://llonix29.pythonanywhere.com//{Randomint}")

and loads with flask

@app.route(f"/{Randomint}",methods=['GET', 'POST'])
def Change():
    return render_template(f'{Randomint}.html',tables=[output.to_html(classes='data')], titles=output.columns.values)

My pythonanywhere route if it helps: https://i.stack.imgur.com/01Xuz.png ,what can i do?

Try using an absolute path to the file in both places, where you write it and when you render the template.