I’m trying to protect anything in that folder from being accessed which is in the ‘protected’ folder unless the user is logged in. When running on localhost, if I click on a url link for a file in that folder then the file downloads (I have instance ‘protected’ folder set as the local location when running on localhost). When then change the location to the path for pythonanywhere and upload then it fails and I get the redirected page. Here is my code:
In the template:
<a href="protected/papers/seag_practice_paper_001.pdf" class="btn btn-primary quizselect">Download</a>
In my routes:
def special_requirement(f):
@wraps(f)
def wrap(*args, **kwargs):
try:
if session['username'] is True:
return f(*args, **kwargs)
else:
return redirect(url_for('contact'))
except:
return redirect(url_for('login'))
return wrap
@app.route('/protected/<path:filename>')
@special_requirement
def protected(filename):
try:
return send_from_directory(
os.path.join(app.instance_path, ''),
filename
)
except:
return redirect(url_for('index'))
When I attempt to download the file from the template with the link, I get redirected to the index page. I was wandering if I had set the instance_path incorrectly as it works when set to the local path location, any idea? Thanks