корневой файл
create_db.py
файлы внутри папки webapp
__init__.py
config.py
model.py
и тд.
__init__.py
from flask import Flask, render_template
from webapp.model import db
from webapp.python_org_news import get_python_news
from webapp.weather import weather_by_city
def create_app():
app = Flask(__name__)
app.config.from_pyfile('config.py')
db.init_app(app)
@app.route('/')
def index():
title = 'Новости Python'
weather = weather_by_city(app.config['WEATHER_DEFAULT_CITY'])
news_list = get_python_news()
return render_template("index.html", page_title=title, weather=weather, news_list=news_list)
return app
config.py
import os
basedir = os.path.abspath(os.path.dirname(__file__))
WEATHER_DEFAULT_CITY = 'Moscow,Russia'
WEATHER_API_KEY = '2de7eab71411420281d172154232305'
WEATHER_URL = '
api.worldweatheronline.com/premium/v1/weather.ashx'
SQLALCHEMY_DATABASE_URI = '
sqlite:///' + os.path.join(basedir, '..', 'webapp.db')
model.py
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
class News(db.Model):
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String, nullable=False)
url = db.Column(db.String, unique=True, nullable=False)
published = db.Column(db.DateTime, nullable=False)
text = db.Column(db.Text, nullable=True)
def __repr__(self):
return ''.format(self.title, self.url)
dreate_db.py
from webapp import db, create_app
db.create_all(app=create_app())