my flask application has been running fine last 24 hours, took offline work on , i'm trying start again , i'm getting error:
traceback (most recent call last): file "runserver.py", line 1, in <module> app import app file "/home/my name/app folder name/app.py", line 15, in <module> views import * file "/home/my name/app folder name/views.py", line 1, in <module> @app.route('/contact', methods=('get', 'post')) nameerror: name 'app' not defined
i running application calling python runserver.py
runserver.py:
from app import app app.run(threaded = true, debug=true, host='0.0.0.0')
views.py: contains of routes, won't post them all, error coming first time app
mentioned in file.
@app.route('/contact', methods=('get', 'post')) def contact(): form = contactform() if request.method == 'post': msg = message("censored, sender='censored', recipients=['censored']) msg.body = """ from: %s <%s>, %s """ % (form.name.data, form.email.data, form.message.data) mail.send(msg) return "><p><br>successfully sent message!</p></body>" elif request.method == 'get': return render_template('contact.html', form=form)
app.py: here top of app.py file, define app = flask(__name__)
import statements.
from flask import flask, request, render_template, redirect, url_for, send_file geopy.geocoders import bing geopy.exc import geocodertimedout import re import urllib bs4 import beautifulsoup openpyxl import load_workbook openpyxl.styles import style, font import os import pandas pd import numpy np import datetime helper_file import * lists import * views import * flask_mail import mail, message forms import contactform global today geolocator = bing('censored') app = flask(__name__)
edit: have made changes suggested in answer below, getting when access page:
not found
the requested url not found on server. if entered url manually please check spelling , try again.
here file structure:
dhlsoftware.com |-static |-style.css |-templates |- seperate html file each page template |-app.py |-forms.py |-helper_file.py |-lists.py |-runserver.py |-views.py
in app.py
should remove from views import *
. instead in views.py
need have from app import app
that bring app views namespace , believe should work you.
Comments
Post a Comment