Cześć,
uczę się flaska i postanowiłem zrobić darmowy kurs z yt. Robię wszystko jak koleś z filmiku, ściągnąłem jego kod i dalej mam ten sam error. Macie jakieś porady jak to naprawić?
Miałem pobranego pythona i anaconde, pythona usunąłem bo na stacku radzili, żeby zostawić jedną z tych dwóch opcji. Dodaje dwa ScreenShoty, błędu i fragmentu kodu do którego błąd daje odniesienie.
Z góry dziękuje za pomoc
link do pobrania całości krótkiego kodu: https://drive.google.com/file/d/1iia4f8ILCj9trXN9V_Y0MeVcTWIwuqos/view
from flask import Flask, render_template, request, redirect
from flask_sqlalchemy import SQLAlchemy
from datetime import datetime
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) #nullable title musi być podany
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)
all_posts = [
{
'title':'Post 1',
'content':'This is a content of Post 1. LAlalalalALLAa',
'author':'Pablo'
},
{
'title':'Post 2',
'content':'This is a content of Post 2. LAlalalalALLAa'
}
]
@app.route('/')
def index():
return render_template('index.html')
@app.route('/posts', methods = ['GET', 'POST'])
def posts():
if request.method == 'POST':
post_title = request.form['title']
post_content = request.form['content']
post_author = request.form['author']
new_post = BlogPost (title = post_title, content = post_content, author = post_author)
db.session.add(new_post)
db.session.commit()
return redirect('/posts')
else:
all_posts = BlogPost.query.order_by(BlogPost.date_posted).all()
return render_template('posts.html', posts = all_posts)
@app.route('/home/users/<string:name>/posts/<int:id>')
def hello(name, id):
return 'Hello ' + name + ', youre id is: ' + str(id)
@app.route('/onlyget', methods = ['GET'])
def get_req():
return 'you can get this webpage.'
if __name__ == '__main__':
app.run(debug = True)
- zdjecieKod.png (148 KB) - ściągnięć: 47
- zdjecieError.png (66 KB) - ściągnięć: 66