please give a runnable sample of your code with the full error text or a clear description of the problem
This is the error am having:
Traceback (most recent call last):
File "manage.py", line 3, in <module>
from thermos import app, db
File "/Users/MAC/dev/thermos/thermos/__init__.py", line 16, in <module>
import views
File "/Users/MAC/dev/thermos/thermos/views.py", line 10, in <module>
@app.route('/index')
File "/Users/MAC/.envs/thermos/lib/python2.7/site-packages/flask/app.py", line 1080, in decorator
self.add_url_rule(rule, endpoint, f, **options)
File "/Users/MAC/.envs/thermos/lib/python2.7/site-packages/flask/app.py", line 64, in wrapper_func
return f(self, *args, **kwargs)
File "/Users/MAC/.envs/thermos/lib/python2.7/site-packages/flask/app.py", line 1051, in add_url_rule
'existing endpoint function: %s' % endpoint)
AssertionError: View function mapping is overwriting an existing endpoint function: index
This is my __init__.py:
import os
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
basedir = os.path.abspath(os.path.dirname(__file__))
app = Flask(__name__)
app.config['SECRET_KEY']= '\xd4\xdf\xac\xf1\x1f\xcbGt\xd0,\xbb\xd9\x02\xaf/+n\x08\x13t\x9fd\x12g'
app.config['SQLALCHEMY_DATABASE_URI'] ='sqlite:///'+ os.path.join(basedir,'thermos.db')
app.config['SQLALCHEMY_TRACK_MODIFICATION'] = False
app.config['DEBUG']= True
db = SQLAlchemy(app)
import models
import views
import os
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
basedir = os.path.abspath(os.path.dirname(__file__))
app = Flask(__name__)
app.config['SECRET_KEY']= 'its_a_secret'
app.config['SQLALCHEMY_DATABASE_URI'] ='sqlite:///'+ os.path.join(basedir,'thermos.db')
app.config['SQLALCHEMY_TRACK_MODIFICATION'] = False
app.config['DEBUG']= True
db = SQLAlchemy(app)
import models
import views
and my manaage.py is this:
#! /usr/bin/env python
from thermos import app, db
from thermos.models import User
from flask_script import Manager, prompt_bool
from thermos import db
from models import User
manager = Manager(app)
@manager.command
def initdb():
db.create_all()
db.session.add(User(username="olatunji",email="olatunji. ayodele@outlook.com"))
db.session.add(User(username="Samuel",email="abiodun@Sam uel@outlook.com"))
db.session.commit()
print 'Initialized the database'
@manager.command
def dropdb():
if prompt_bool(
"Are you sure you want to lose all your data"):
db.drop_all()
print 'Dropped the database'
if __name__ == '__main__':
manager.run()
and my model.py is this:
from datetime import datetime
from sqlalchemy import desc
from thermos import db
class Bookmark(db.Model):
id = db.Column(db.Integer,primary_key=True)
url = db.Column(db.Text,nullable=False)
date = db.Column(db.DateTime,default=datetime.utcnow)
description = db.Column(db.String(300))
user_id = db.Column(db.Integer,db.ForeignKey('user.id'),nullable=False)
@staticmethod
def newest(num):
return Bookmark.query.order_by(desc(Bookmark.date)).limit(num)
def __repr__(self):
return "<Bookmark '{}': '{}'>".format(self.description,self.url)
class User(db.Model):
id = db.Column(db.Integer,primary_key=True)
username = db.Column(db.String(80),unique=True)
email = db.Column(db.String(120),unique=True)
bookmarks = db.relationship('Bookmark',backref='user',lazy='dynamic')
def __repr__(self):
return "<User '{}'>".format(self.username)
how can I correct this error?
This is the error am having:
Traceback (most recent call last):
File "manage.py", line 3, in <module>
from thermos import app, db
File "/Users/MAC/dev/thermos/thermos/__init__.py", line 16, in <module>
import views
File "/Users/MAC/dev/thermos/thermos/views.py", line 10, in <module>
@app.route('/index')
File "/Users/MAC/.envs/thermos/lib/python2.7/site-packages/flask/app.py", line 1080, in decorator
self.add_url_rule(rule, endpoint, f, **options)
File "/Users/MAC/.envs/thermos/lib/python2.7/site-packages/flask/app.py", line 64, in wrapper_func
return f(self, *args, **kwargs)
File "/Users/MAC/.envs/thermos/lib/python2.7/site-packages/flask/app.py", line 1051, in add_url_rule
'existing endpoint function: %s' % endpoint)
AssertionError: View function mapping is overwriting an existing endpoint function: index
This is my __init__.py:
import os
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
basedir = os.path.abspath(os.path.dirname(__file__))
app = Flask(__name__)
app.config['SECRET_KEY']= '\xd4\xdf\xac\xf1\x1f\xcbGt\xd0,\xbb\xd9\x02\xaf/+n\x08\x13t\x9fd\x12g'
app.config['SQLALCHEMY_DATABASE_URI'] ='sqlite:///'+ os.path.join(basedir,'thermos.db')
app.config['SQLALCHEMY_TRACK_MODIFICATION'] = False
app.config['DEBUG']= True
db = SQLAlchemy(app)
import models
import views
import os
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
basedir = os.path.abspath(os.path.dirname(__file__))
app = Flask(__name__)
app.config['SECRET_KEY']= 'its_a_secret'
app.config['SQLALCHEMY_DATABASE_URI'] ='sqlite:///'+ os.path.join(basedir,'thermos.db')
app.config['SQLALCHEMY_TRACK_MODIFICATION'] = False
app.config['DEBUG']= True
db = SQLAlchemy(app)
import models
import views
and my manaage.py is this:
#! /usr/bin/env python
from thermos import app, db
from thermos.models import User
from flask_script import Manager, prompt_bool
from thermos import db
from models import User
manager = Manager(app)
@manager.command
def initdb():
db.create_all()
db.session.add(User(username="olatunji",email="olatunji. ayodele@outlook.com"))
db.session.add(User(username="Samuel",email="abiodun@Sam uel@outlook.com"))
db.session.commit()
print 'Initialized the database'
@manager.command
def dropdb():
if prompt_bool(
"Are you sure you want to lose all your data"):
db.drop_all()
print 'Dropped the database'
if __name__ == '__main__':
manager.run()
and my model.py is this:
from datetime import datetime
from sqlalchemy import desc
from thermos import db
class Bookmark(db.Model):
id = db.Column(db.Integer,primary_key=True)
url = db.Column(db.Text,nullable=False)
date = db.Column(db.DateTime,default=datetime.utcnow)
description = db.Column(db.String(300))
user_id = db.Column(db.Integer,db.ForeignKey('user.id'),nullable=False)
@staticmethod
def newest(num):
return Bookmark.query.order_by(desc(Bookmark.date)).limit(num)
def __repr__(self):
return "<Bookmark '{}': '{}'>".format(self.description,self.url)
class User(db.Model):
id = db.Column(db.Integer,primary_key=True)
username = db.Column(db.String(80),unique=True)
email = db.Column(db.String(120),unique=True)
bookmarks = db.relationship('Bookmark',backref='user',lazy='dynamic')
def __repr__(self):
return "<User '{}'>".format(self.username)
how can I correct this error?