Forums

500 Internal server error

My app works perfectly fine on my local host but when I hosted it on python anywhere it is showing internal server error ERROR LOG

Traceback (most recent call last): File "/usr/lib/python3.6/site-packages/flask/app.py", line 1813, in full_dispatch_request rv = self.dispatch_request() File "/usr/lib/python3.6/site-packages/flask/app.py", line 1791, in dispatch_request self.raise_routing_exception(req) File "/usr/lib/python3.6/site-packages/flask/app.py", line 1774, in raise_routing_exception raise request.routing_exception File "/usr/lib/python3.6/site-packages/flask/ctx.py", line 336, in match_request self.url_adapter.match(return_rule=True) File "/usr/lib/python3.6/site-packages/werkzeug/routing.py", line 1581, in match raise NotFound() werkzeug.exceptions.NotFound: 404 Not Found: The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again. NO MATCH During handling of the above exception, another exception occurred: NO MATCH Traceback (most recent call last): File "/usr/lib/python3.6/site-packages/flask/app.py", line 2292, in wsgi_app response = self.full_dispatch_request() File "/usr/lib/python3.6/site-packages/flask/app.py", line 1815, in full_dispatch_request rv = self.handle_user_exception(e) File "/usr/lib/python3.6/site-packages/flask/app.py", line 1713, in handle_user_exception return self.handle_http_exception(e) File "/usr/lib/python3.6/site-packages/flask/app.py", line 1644, in handle_http_exception return handler(e) File "/home/shiva1024/mysite/flask_app.py", line 83, in page_not_found File "/usr/lib/python3.6/site-packages/flask/templating.py", line 134, in render_template return _render(ctx.app.jinja_env.get_or_select_template(template_name_or_list), File "/usr/lib/python3.6/site-packages/jinja2/environment.py", line 869, in get_or_select_template return self.get_template(template_name_or_list, parent, globals) File "/usr/lib/python3.6/site-packages/jinja2/environment.py", line 830, in get_template return self._load_template(name, self.make_globals(globals)) File "/usr/lib/python3.6/site-packages/jinja2/environment.py", line 804, in _load_template template = self.loader.load(self, name, globals) File "/usr/lib/python3.6/site-packages/jinja2/loaders.py", line 113, in load source, filename, uptodate = self.get_source(environment, name) File "/usr/lib/python3.6/site-packages/flask/templating.py", line 58, in get_source return self._get_source_fast(environment, template) File "/usr/lib/python3.6/site-packages/flask/templating.py", line 86, in _get_source_fast raise TemplateNotFound(template) jinja2.exceptions.TemplateNotFound: 404.html

flask_app.py

import io import json import os

import datetime import time from flask import Flask, render_template, request, url_for, redirect

app = Flask(name) resume_pdf_link = 'https://drive.google.com/open?id=0B2BrrDjIiyvmcWp5T194cy00UmM'

@app.route('/') def index(): age = int((datetime.date.today() - datetime.date(1999, 10, 24)).days / 365) return render_template('home.html', age=age)

@app.route('/timeline') def timeline(): return render_template('timeline.html', resume_pdf_link=resume_pdf_link)

@app.route('/skills') def skills(): return render_template('skills.html')

@app.route('/projects') def projects(): data = get_static_json("static/projects.json")['projects'] data.sort(key=order_projects_by_weight, reverse=True)

tag = request.args.get('tags')
if tag is not None:
    data = [project for project in data if tag.lower() in [project_tag.lower() for project_tag in project['tags']]]

return render_template('projects.html', projects=data, tag=tag)

def order_projects_by_weight(projects): try: return int(projects['weight']) except KeyError: return 0

@app.route('/projects/<title>') def project(title): projects = get_static_json("static/projects.json")['projects'] experiences = get_static_json("static/experiences.json")['experiences']

in_project = next((p for p in projects if p['link'] == title), None)
in_exp = next((p for p in experiences if p['link'] == title), None)

if in_project is None and in_exp is None:
    return render_template('404.html'), 404
# fixme: choose the experience one for now, cuz I've done some shite hardcoding here.
elif in_project is not None and in_exp is not None:
    selected = in_exp
elif in_project is not None:
    selected = in_project
else:
    selected = in_exp

# load html if the json file doesn't contain a description
if 'description' not in selected:
    path = "static" if in_exp is not None else "static"
    selected['description'] = io.open(get_static_file(
        'static/%s.html' % (selected['link'])), "r", encoding="utf-8").read()
    print(selected)
return render_template('project.html', project=selected)

@app.errorhandler(404) def page_not_found(e): return render_template('404.html'), 404

def get_static_file(path): site_root = os.path.realpath(os.path.dirname(file)) return os.path.join(site_root, path)

def get_static_json(path): return json.load(open(get_static_file(path)))

""" Specific URLs """

@app.route('/upload', methods=['POST']) def upload_file(): if request.method == 'POST': f = request.files['file'] os.makedirs('./static/', exist_ok=True) file_name = 'upload-%s' % time.strftime("%Y-%m-%d-%H-%M-%S") f.save('./static/uploads/%s' % file_name) return redirect(url_for('predict_fifa', name=file_name))

name = request.args.get('name')
path = './static/uploads/%s' % name
print('------------------')
print(path)
if not os.path.exists(path):
    return "File doesn't exist, soz, go to the home page! %s" % path

app.run(host="127.0.0.1", port=5000, debug=True)

Please help this is my first web hosting

It looks to me like you're getting a 404 error (probably because you are trying to access a URL where you don't have a view) but since you do not have the 404.html template where Flask can find it, you get an exception. You need a 404.html template in the Flask templates directory.