title: AssertionError: View function mapping is overwriting an existing endpoint function: home - flask
body: <p><a href="https://i.stack.imgur.com/MNkbU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MNkbU.png" alt="enter image description here"></a></p>
  
  <p>I'm trying to work my way through <a href="http://code.tutsplus.com/tutorials/an-introduction-to-pythons-flask-framework--net-28822" rel="nofollow noreferrer">http://code.tutsplus.com/tutorials/an-introduction-to-pythons-flask-framework--net-28822</a></p>
  
  <pre><code>C:\envs\virtalenvs\flask_mini\Scripts\python.exe C:/envs/r2/mini2/intro_to_flask/__init__.py
  C:\envs\virtalenvs\flask_mini\lib\site-packages\flask_sqlalchemy\__init__.py:800: UserWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future.  Set it to True to suppress this warning.
    warnings.warn('SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future.  Set it to True to suppress this warning.')
  Traceback (most recent call last):
    File "C:/envs/r2/mini2/intro_to_flask/__init__.py", line 13, in &lt;module&gt;
      from routes import mail
    File "C:\envs\r2\mini2\intro_to_flask\routes.py", line 9, in &lt;module&gt;
      @app.route('/')
    File "C:\envs\virtalenvs\flask_mini\lib\site-packages\flask\app.py", line 1013, in decorator
      self.add_url_rule(rule, endpoint, f, **options)
    File "C:\envs\virtalenvs\flask_mini\lib\site-packages\flask\app.py", line 62, in wrapper_func
      return f(self, *args, **kwargs)
    File "C:\envs\virtalenvs\flask_mini\lib\site-packages\flask\app.py", line 984, in add_url_rule
      'existing endpoint function: %s' % endpoint)
  AssertionError: View function mapping is overwriting an existing endpoint function: home
  </code></pre>
  
  <p>the routes.py file is:</p>
  
  <pre><code>from intro_to_flask import app
  from flask import render_template, request, flash, session, url_for, redirect
  from forms import ContactForm, SignupForm, SigninForm
  from flask.ext.mail import Message, Mail
  from models import db, User
  
  mail = Mail()
  
  
  @app.route('/')
  def home():
      return render_template('home.html')
  
  
  @app.route('/about')
  def about():
      return render_template('about.html')
  
  
  @app.route('/contact', methods=['GET', 'POST'])
  def contact():
      form = ContactForm()
  
      if request.method == 'POST':
          if form.validate() == False:
              flash('All fields are required.')
              return render_template('contact.html', form=form)
          else:
              msg = Message(form.subject.data, sender='contact@example.com', recipients=['your_email@example.com'])
              msg.body = """
              From: %s &lt;%s&gt;
              %s
              """ % (form.name.data, form.email.data, form.message.data)
              mail.send(msg)
  
              return render_template('contact.html', success=True)
  
      elif request.method == 'GET':
          return render_template('contact.html', form=form)
  
  
  @app.route('/signup', methods=['GET', 'POST'])
  def signup():
      form = SignupForm()
  
      if 'email' in session:
          return redirect(url_for('profile'))
  
      if request.method == 'POST':
          if form.validate() == False:
              return render_template('signup.html', form=form)
          else:
              newuser = User(form.firstname.data, form.lastname.data, form.email.data, form.password.data)
              db.session.add(newuser)
              db.session.commit()
  
              session['email'] = newuser.email
              return redirect(url_for('profile'))
  
      elif request.method == 'GET':
          return render_template('signup.html', form=form)
  
  
  @app.route('/profile')
  def profile():
      if 'email' not in session:
          return redirect(url_for('signin'))
  
      user = User.query.filter_by(email=session['email']).first()
  
      if user is None:
          return redirect(url_for('signin'))
      else:
          return render_template('profile.html')
  
  
  @app.route('/signin', methods=['GET', 'POST'])
  def signin():
      form = SigninForm()
  
      if 'email' in session:
          return redirect(url_for('profile'))
  
      if request.method == 'POST':
          if form.validate() == False:
              return render_template('signin.html', form=form)
          else:
              session['email'] = form.email.data
              return redirect(url_for('profile'))
  
      elif request.method == 'GET':
          return render_template('signin.html', form=form)
  
  
  @app.route('/signout')
  def signout():
      if 'email' not in session:
          return redirect(url_for('signin'))
  
      session.pop('email', None)
      return redirect(url_for('home'))
  </code></pre>
  
  <p>What could be causing this?</p>
  
  <p>Edit:</p>
  
  <p>When I put the about function first I get:</p>
  
  <pre><code> AssertionError: View function mapping is overwriting an existing endpoint function: about
  </code></pre>
  
  <p>So I think the problem may be in the import statements or at least before the first route:</p>
  
  <pre><code>from intro_to_flask import app
  from flask import render_template, request, flash, session, url_for, redirect
  from forms import ContactForm, SignupForm, SigninForm
  from flask.ext.mail import Mail, Message
  from models import db, User
  
  mail = Mail()
  </code></pre>
  
  <p>edit 2:</p>
  
  <pre><code>from flask import Flask
  
  app = Flask(__name__)
  
  app.secret_key = 'development key'
  
  app.config["MAIL_SERVER"] = "smtp.gmail.com"
  app.config["MAIL_PORT"] = 465
  app.config["MAIL_USE_SSL"] = True
  app.config["MAIL_USERNAME"] = 'contact@example.com'
  app.config["MAIL_PASSWORD"] = 'your-password'
  
  from routes import mail
  mail.init_app(app)
  
  app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://your-username:your-password@localhost/development'
  
  from models import db
  db.init_app(app)
  
  import intro_to_flask.routes
  </code></pre>