Hello, I am new to PythonAnywhere and am trying to setup a database to store the "members" who register on the site. I'm stuck and would really appreciate some help! Thanks!
ps: you are welcome to look at any files on my account
Hello, I am new to PythonAnywhere and am trying to setup a database to store the "members" who register on the site. I'm stuck and would really appreciate some help! Thanks!
ps: you are welcome to look at any files on my account
Describe the problem that you're having and we'll try to help you.
Hi, I have tried to connect and follow tutorials, but they have not worked. I just cant get it to work.. I don't really know what the problem is but everything seems to be going wrong.
We need to know the code you try to run and the error you are getting to help you.
Heres the error log:
Error running WSGI application
NameError: name 'weycc' is not defined
File "/var/www/weycc_pythonanywhere_com_wsgi.py", line 16, in <module>
from web import app as application # noqa
File "/home/weycc/mysite/web.py", line 9, in <module>
URI = "mysql://{username}:{password}@{hostname}/{databasename}".format(username=weycc,
That's from the error log. Heres the code:
from flask import Flask, redirect, url_for, render_template, request, session, flash
from datetime import timedelta
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
URI = "mysql://{username}:{password}@{hostname}/{databasename}".format(username=weycc,
password='climate!',
hostname='weycc.mysql.pythonanywhere-services.com',
databasename='weycc$Members')
app.permanent_session_lifetime = timedelta(days=100)
db = SQLAlchemy(app)
class Members(db.Model):
_id = db.Column("id", db.Integer, primary_key=True)
name = db.Column(db.String(50))
email = db.Column(db.String(100))
def __init__(self, name, email):
self.name = name
self.email = email
@app.route("/")
def home():
return render_template("index.html")
@app.route("/events")
def events():
return render_template("events.html")
@app.route("/newevent")
def newevent():
return render_template("newevent.html")
@app.route("/meetthemembers")
def members():
return render_template("members.html")
@app.route("/aboutus")
def aboutus():
return render_template("aboutus.html")
@app.route("/register", methods=["POST", "GET"])
def register():
render_template("register.html")
if request.method == "POST":
name = ["name"]
email = ["email"]
name = request.form["name"]
email = request.form["email"]
mbr = Members(name, email)
db.session.add(mbr)
db.session.commit()
return redirect(url_for("home"))
else:
return render_template("register.html")
@app.route("/committees")
def committees():
return render_template("committees.html")
if __name__ == "__main__":
db.create_all()
app.run(debug = True)
The indentation is messed up on here but it is correct in the real file. Thanks!
[edit by admin: formatting]
In this line:
URI = "mysql://{username}:{password}@{hostname}/{databasename}".format(username=weycc,
...you are using a variable called weycc
, but you have not defined it. If the username you want to use is the string "weycc"
, you need to put it in quotes.
Thank you.. i tried that but still got the same error.
URI = "mysql://{username}:{password}@{hostname}/{databasename}".format(username="weycc",
Did you reload your web app after making the change?
Oh that was stupid of me! The website is working now. I'm still having trouble with my database. I believe I have to do something with a virtual env but I'm having trouble with that. Thanks
Warning: No virtualenv detected at this path. Do you need to create it?
It looks like you have a broken virtualenv (there are libs for two Python versions, which is certainly something you don't want to have in a venv). I'd suggest remove that venv completely, and create one with Python 3.6 (which matches your web app Python).