Skip to content
Snippets Groups Projects
Commit 5194403d authored by Ethan Clay (Student)'s avatar Ethan Clay (Student)
Browse files

Copy layout from DO guide

parent 814cf3e9
Branches
No related tags found
No related merge requests found
Showing with 81 additions and 7 deletions
File added
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello_world():
return "<p>Hello, World!</p>"
\ No newline at end of file
# Boilerplate code taken from https://www.digitalocean.com/community/tutorials/how-to-structure-a-large-flask-application-with-flask-blueprints-and-flask-sqlalchemy
from flask import Flask
from config import Config
def create_app(config_class=Config):
app = Flask(__name__)
app.config.from_object(config_class)
# Initialize Flask extensions here
# Register blueprints here
from app.main import bp as main_bp
app.register_blueprint(main_bp)
from app.posts import bp as posts_bp
app.register_blueprint(posts_bp, url_prefix='/posts')
@app.route('/test/')
def test_page():
return '<h1>Testing the Flask Application Factory Pattern</h1>'
return app
\ No newline at end of file
File added
from flask import Blueprint
bp = Blueprint('main', __name__)
from app.main import routes
\ No newline at end of file
File added
File added
from flask import render_template
from app.main import bp
@bp.route('/')
def index():
return render_template('index.html')
\ No newline at end of file
from flask import Blueprint
bp = Blueprint('posts', __name__)
from app.posts import routes
\ No newline at end of file
File added
File added
from flask import render_template
from app.posts import bp
@bp.route('/')
def index():
return render_template('posts/index.html')
<body>
<nav>
<a href="{{ url_for('main.index') }}">HOME</a>
<a href="#">Posts</a>
</nav>
<hr>
<div class="content">
{% block content %} {% endblock %}
</div>
</body>
\ No newline at end of file
{% extends 'base.html' %}
{% block content %}
<div class="content">
<h2>Index.html</h2>
</div>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% block content %}
<div class="content">
<h2>Index of posts.html</h2>
</div>
{% endblock %}
\ No newline at end of file
import os
basedir = os.path.abspath(os.path.dirname(__file__))
class Config:
SECRET_KEY = os.environ.get('SECRET_KEY')
SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URI')\
or 'sqlite:///' + os.path.join(basedir, 'app.db')
SQLALCHEMY_TRACK_MODIFICATIONS = False
\ No newline at end of file
/* Core CSS Style types */
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment