Я очень новичок в веб-фреймворке и python. Я пытаюсь выучить flask и сталкиваюсь с огромной проблемой.
Я пытаюсь импортировать БД с помощью SQLAlchemy db.model .. но по команде терминала он не позволяет мне.
Я получаю сообщение об ошибке: «От» не распознается как внутренняя или внешняя команда, работающая программа или пакетный файл.
У меня есть путь к каталогу на моем компьютере, но я не знаю, в чем проблема.
вот мой python код:
from flask import Flask, render_template
from flask_sqlalchemy import SQLAlchemy
from datetime import datetime
# References the file __name__
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:/// posts.db'
db = SQLAlchemy(app)
class BlogPost(db.Model):
id = db.Column(db.integer, primary_key=True)
title = db.Column(db.String(100), nullable=False)
content = db.Column(db.Text, nullable=False)
author = db.Column(db.String(20), nullable=False, default='N/A')
date_posted = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
def __repr__(self):
return 'Blog post ' + str(self.id)
# Url routing - decorator
# Domain should be inside
# Templates front end work of flask. Design and others
all_posts = [
{
'title': 'Post 1',
'content': 'This is the content of post 1.',
'author': 'Chris'
},
{
'title': 'Post 2',
'content': 'This is the content of post 2.',
}
]
@app.route('/')
def index():
return render_template('index.html')
@app.route('/posts')
def posts():
return render_template('posts.html', posts=all_posts)
@app.route('/home/<string:name>')
def hello(name):
return "Hello, " + name
# define allow request method get, post
@app.route('/onlyget', methods=['GET', 'POST'])
def get_req():
return 'You can only get this web page 2.'
# Allow us to give full block of error once they have one
if __name__ == "__main__":
app.run(debug=True)