Python Forum
View function mapping is overwriting an existing endpoint function: index
Thread Rating:
  • 2 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
View function mapping is overwriting an existing endpoint function: index
#11
sorry, at the moment I can not offer advise, structure looks fine and in accordance with the recommendation
I haven't use flask_script and frankly for what you use it here I would simply use separate script, without link/import of app that seems to cause the problem.
As a side note - maybe it's better to migrate to new Flask CLI
Reply
#12
(Oct-09-2017, 06:28 AM)buran Wrote: sorry, at the moment I can not offer advise, structure looks fine and in accordance with the recommendation
I haven't use flask_script and frankly for what you use it here I would simply use separate script, without link/import of app that seems to cause the problem.
As a side note - maybe it's better to migrate to new Flask CLI
Thanks so much.I will work on this and let you know how it turns out.
Smile
Reply
#13
(Oct-09-2017, 06:28 AM)buran Wrote: sorry, at the moment I can not offer advise, structure looks fine and in accordance with the recommendation
I haven't use flask_script and frankly for what you use it here I would simply use separate script, without link/import of app that seems to cause the problem.
As a side note - maybe it's better to migrate to new Flask CLI
Thanks once again buran and others.
I have learnt a lot on this error.
As you said,the code and structure is fine.However, it is difficult to pin point what is causing the error.I have check the code I posted earlier the one am posting now.I found no real difference.

This is the __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['SQLALCHEMY_DATABASE_URI']= 'sqlite:///' + os.path.join(basedir,'thermos.db')
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['DEBUG'] = True
db = SQLAlchemy(app)

import models
import views
and manage.py:
#! /usr/bin/env python

from thermos import app,db
from thermos.models import User
from flask_script import Manager,prompt_bool

manager = Manager(app)

@manager.command
def initdb():
    db.create_all()
    db.session.add(User(username='olatunji',email='[email protected]'))
    db.session.add(User(username='ayobami',email='[email protected]'))
    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 views.py:
from flask import render_template,flash,redirect,url_for

from thermos import app,db
from forms import BookmarkForm
from models import User,Bookmark

def logged_in_user():
    return User.query.filter_by(username='olatunji').first()


@app.route('/index')
def index():
    return render_template('index.html',new_bookmarks=Bookmark.newest(5))

@app.route("/add",methods=['GET','POST'])
def add():
    form = BookmarkForm()
    if form.validate_on_submit():
        url = form.url.data
        description =form.description.data
        bm = Bookmark(user=logged_in_user(),url=url,description=description)
        db.session.add(bm)
        db.session.commit()
        flash("Stored '{}'".format(description))
        return redirect(url_for('index'))
    return render_template("add.html",form=form)
   
@app.errorhandler(404)
def page_not_found(e):
    return render_template('404.html'),404

@app.errorhandler(500)
def server_error(e):
    return render_template('500.html'),500


if __name__ == '__main__':
    app.run(debug=False)
The new code is running without throwing the error.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  The function of double underscore back and front in a class function name? Pedroski55 9 563 Feb-19-2024, 03:51 PM
Last Post: deanhystad
  Variable for the value element in the index function?? Learner1 8 551 Jan-20-2024, 09:20 PM
Last Post: Learner1
  Mapping a value to an interval JazonKuer 12 1,846 Mar-17-2023, 07:59 PM
Last Post: Gribouillis
  Index Function not recognized in Python 3 Peter_B_23 1 1,118 Jan-08-2023, 04:52 AM
Last Post: deanhystad
  access is denied error 5 for network drive mapping ? ahmedbarbary 2 1,731 Aug-17-2022, 10:09 PM
Last Post: ahmedbarbary
  Requests Session Overwriting and cookie jar muzikman 0 1,267 Dec-13-2021, 02:22 PM
Last Post: muzikman
  Exit function from nested function based on user input Turtle 5 2,859 Oct-10-2021, 12:55 AM
Last Post: Turtle
  Mapping a range ebolisa 5 3,416 Jun-12-2021, 11:17 PM
Last Post: ebolisa
Question Stopping a parent function from a nested function? wallgraffiti 1 3,621 May-02-2021, 12:21 PM
Last Post: Gribouillis
Question exiting the outer function from the inner function banidjamali 3 3,466 Feb-27-2021, 09:47 AM
Last Post: banidjamali

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020