Vidyuth
Vidyuth

Reputation: 35

attribute error in Flask when I run (AttributeError: 'NoneType' object has no attribute 'run' )

I'm Doing the tutorial (https://www.youtube.com/watch?v=dam0GPOAvVI&t=2412s) it was working nicely since there was a problem I don't what.When I run the main.py

Traceback (most recent call last):
  File "c:\Users\admin\Documents\Flask\main.py", line 6, in <module>
    app.run(debug=True)
AttributeError: 'NoneType' object has no attribute 'run'
PS C:\Users\admin\Documents\Flask> 

And the website isn't comming

This site can’t be reached
127.0.0.1 refused to connect.

It will really helpful if u find out why I'm struglling with it Flask/main.py

from website import create_app

app = create_app()

if __name__ == '__main__':
    app.run(debug=True)

website/init.py

from flask import Flask

def create_app():
    app = Flask(__name__)
    app.config['SECRET_KEY'] = 'hello'

    from website.views import views
    from website.auth import auth

    app.register_blueprint(views, url_prefix='/')
    app.register_blueprint(auth, url_prefix='/')

website/views.py

from flask import Blueprint, render_template  

views = Blueprint('views', __name__)

@views.route('/')
def home():
    return render_template("home.html")

website/auth.py

from flask import Blueprint, render_template  

auth = Blueprint('auth', __name__)

@auth.route('/login')
def login():
    return render_template('login.html')

@auth.route('/logout')
def logout():
    return "<p>Logout</p>"

@auth.route('/sign-up')
def sign_up():
    return render_template('sign_up.html')

templates/base.html

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <link
      rel="stylesheet"
      href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
      integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh"
      crossorigin="anonymous"
    />
    <link
      rel="stylesheet"
      href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"
      crossorigin="anonymous"
    />

    <title>{% block title %}Home{% endblock %}</title>
  </head>
  <body>
    <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
      <button
        class="navbar-toggler"
        type="button"
        data-toggle="collapse"
        data-target="#navbar"
      >
        <span class="navbar-toggler-icon"></span>
      </button>
      <div class="collapse navbar-collapse" id="navbar">
        <div class="navbar-nav">
          <a class="nav-item nav-link" id="home" href="/">Home</a>
          <a class="nav-item nav-link" id="logout" href="/logout">Logout</a>
          <a class="nav-item nav-link" id="login" href="/login">Login</a>
          <a class="nav-item nav-link" id="signUp" href="/sign-up">Sign Up</a>
        </div>
      </div>
    </nav>

    <div class="container">
    {% block content %} 
    {% endblock %}
    </div>
    <script
      src="https://code.jquery.com/jquery-3.2.1.slim.min.js"
      integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"
      crossorigin="anonymous"
    ></script>
    <script
      src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"
      integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"
      crossorigin="anonymous"
    ></script>
    <script
      src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"
      integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
      crossorigin="anonymous"
    ></script>

    <script
      type="text/javascript"
      src="{{ url_for('static', filename='index.js') }}"
    ></script>
  </body>
</html>

template/home.html

{% extends "base.html" %} {% block title %}Home{% endblock %}


{% block content %} 
<center>   
    <h1> This Is the home page</h1>
</center>>
{% endblock %}

template/login.html

{% extends "base.html" %} {% block title %}Login{% endblock %}


{% block content %} 
<center>   
    <h1> This Is the login page</h1>
</center>>
{% endblock %}

template/sign_up.html

{% extends "base.html" %} {% block title %}Sign Up{% endblock %}


{% block content %} 
<center>   
    <h1> This Is the sign up page</h1>
</center>>
{% endblock %}

Please help me

Upvotes: 2

Views: 3034

Answers (1)

user5305519
user5305519

Reputation: 3226

At the end of website/init.py, you need to include

def create_app():
    # your other code

    return app # add this

create_app() in Flask/main.py currently returns nothing (None).

Upvotes: 3

Related Questions