A blog application in python using Flask.
techwithtim / flask-blog-tutorial Goto Github PK
View Code? Open in Web Editor NEWA blog application in python using Flask.
A blog application in python using Flask.
It is not possible to delete all posts when there are multiple posts created by one user.
In turtorial3 file, here is no logout.html file in the templates file but there is a reference "href="/logout" in base.html in line 30
I don't know if I am right or completely wrong about this.
If I am wrong, sorry for your waste of time
I am getting the following error when runing the create_function
function:
Traceback (most recent call last): File "c:\Users\aalba\OneDrive\Documents\techwithtim_Flask\app.py", line 1, in <module> from website import create_app ImportError: cannot import name 'create_app' from 'website' (c:\Users\aalba\OneDrive\Documents\techwithtim_Flask\website\__init__.py)
I believe it is something silly. The code is exactly the same could it be something with the path variable or venv?
Hallo Tim,
corrected for the code in the file views.py line 42 in the tutorial,
elif current_user.id != post.id: --> elif current_user.id != post.author:
CMIIW.
When you delete a post, create a new one with the same id as the old post, the comments from the old post show up on the new post.
Hi Tim!
The default argument of the column date should be a function, not the function response.
You wrote: "default=func.now()"
But you should write: "default=func.now" (pass the function as an argument…)
I am getting this error in tutorial 2 and I am unable to create the database to store the user sign-up info
from flask_sqlalchemy import SQLAlchemy
from .extension import SQLAlchemy
from .model import _QueryProperty
class DefaultMeta(BindMetaMixin, NameMetaMixin, sa.orm.DeclarativeMeta):
AttributeError: module 'sqlalchemy.orm' has no attribute 'DeclarativeMeta'
from flask import Blueprint, render_template
from flask_login import login_required, current_user
views = Blueprint("views", name)
@views.route("/")
def base():
return render_template("base.html", name="guest")
@views.route("/home")
def home():
return render_template("home.html", name=current_user.username)
Hi, I am having an error while running your final tutorial 5 while signing or login in, it looks like it can't create or identify any database! Can you please take a look, at where is the problem? Thanks in advance.
OperationalError
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: user
[SQL: SELECT user.id AS user_id, user.email AS user_email, user.username AS user_username, user.password AS user_password, user.date_created AS user_date_created
FROM user
WHERE user.email = ?
LIMIT ? OFFSET ?]
[parameters: ('[email protected]', 1, 0)]
(Background on this error at: https://sqlalche.me/e/20/e3q8)
Traceback (most recent call last)
File "/Users/arnob_t78/.pyenv/versions/3.11.6/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 1960, in _exec_single_context
self.dialect.do_execute(
^
File "/Users/arnob_t78/.pyenv/versions/3.11.6/lib/python3.11/site-packages/sqlalchemy/engine/default.py", line 924, in do_execute
cursor.execute(statement, parameters)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The above exception was the direct cause of the following exception:
File "/Users/arnob_t78/.pyenv/versions/3.11.6/lib/python3.11/site-packages/flask/app.py", line 1488, in call
return self.wsgi_app(environ, start_response)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/arnob_t78/.pyenv/versions/3.11.6/lib/python3.11/site-packages/flask/app.py", line 1466, in wsgi_app
response = self.handle_exception(e)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/arnob_t78/.pyenv/versions/3.11.6/lib/python3.11/site-packages/flask/app.py", line 1463, in wsgi_app
response = self.full_dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/arnob_t78/.pyenv/versions/3.11.6/lib/python3.11/site-packages/flask/app.py", line 872, in full_dispatch_request
rv = self.handle_user_exception(e)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/arnob_t78/.pyenv/versions/3.11.6/lib/python3.11/site-packages/flask/app.py", line 870, in full_dispatch_request
rv = self.dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/arnob_t78/.pyenv/versions/3.11.6/lib/python3.11/site-packages/flask/app.py", line 855, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) # type: ignore[no-any-return]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/arnob_t78/myProjects/testWebApp/website/auth.py", line 38, in sign_up
email_exists = User.query.filter_by(email=email).first()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/arnob_t78/.pyenv/versions/3.11.6/lib/python3.11/site-packages/sqlalchemy/orm/query.py", line 2727, in first
return self.limit(1)._iter().first() # type: ignore
^^^^^^^^^^^^^^^^^^^^^
File "/Users/arnob_t78/.pyenv/versions/3.11.6/lib/python3.11/site-packages/sqlalchemy/orm/query.py", line 2826, in _iter
result: Union[ScalarResult[_T], Result[_T]] = self.session.execute(
File "/Users/arnob_t78/.pyenv/versions/3.11.6/lib/python3.11/site-packages/sqlalchemy/orm/session.py", line 2306, in execute
return self._execute_internal(
File "/Users/arnob_t78/.pyenv/versions/3.11.6/lib/python3.11/site-packages/sqlalchemy/orm/session.py", line 2191, in _execute_internal
result: Result[Any] = compile_state_cls.orm_execute_statement(
File "/Users/arnob_t78/.pyenv/versions/3.11.6/lib/python3.11/site-packages/sqlalchemy/orm/context.py", line 293, in orm_execute_statement
result = conn.execute(
File "/Users/arnob_t78/.pyenv/versions/3.11.6/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 1408, in execute
return meth(
File "/Users/arnob_t78/.pyenv/versions/3.11.6/lib/python3.11/site-packages/sqlalchemy/sql/elements.py", line 513, in _execute_on_connection
return connection._execute_clauseelement(
File "/Users/arnob_t78/.pyenv/versions/3.11.6/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 1630, in _execute_clauseelement
ret = self._execute_context(
File "/Users/arnob_t78/.pyenv/versions/3.11.6/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 1839, in _execute_context
return self._exec_single_context(
File "/Users/arnob_t78/.pyenv/versions/3.11.6/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 1979, in _exec_single_context
self._handle_dbapi_exception(
^
File "/Users/arnob_t78/.pyenv/versions/3.11.6/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 2335, in _handle_dbapi_exception
raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/arnob_t78/.pyenv/versions/3.11.6/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 1960, in _exec_single_context
self.dialect.do_execute(
^
File "/Users/arnob_t78/.pyenv/versions/3.11.6/lib/python3.11/site-packages/sqlalchemy/engine/default.py", line 924, in do_execute
cursor.execute(statement, parameters)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: user
[SQL: SELECT user.id AS user_id, user.email AS user_email, user.username AS user_username, user.password AS user_password, user.date_created AS user_date_created
FROM user
WHERE user.email = ?
LIMIT ? OFFSET ?]
[parameters: ('[email protected]', 1, 0)]
(Background on this error at: https://sqlalche.me/e/20/e3q8)
There is a warning when running and restarting the server.
Warning:
C:\Users\username_that_i_am_not_disclosing\Cloned GIT Stuff\Flask-Blog-Tutorial\venv\lib\site-
packages\flask_sqlalchemy\__init__.py:873: FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant
overhead and will be disabled by default in the future. Set it to True or False to suppress this warning.
'SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and '
App 2146154 output: /opt/cpanel/ea-ruby24/root/usr/share/passenger/helper-scripts/wsgi-loader.py:26: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
App 2146154 output: import sys, os, re, imp, threading, signal, traceback, socket, select, struct, logging, errno
App 2146154 output: Traceback (most recent call last):
App 2146154 output: File "/opt/cpanel/ea-ruby24/root/usr/share/passenger/helper-scripts/wsgi-loader.py", line 369, in
App 2146154 output: app_module = load_app()
App 2146154 output: File "/opt/cpanel/ea-ruby24/root/usr/share/passenger/helper-scripts/wsgi-loader.py", line 76, in load_app
App 2146154 output: return imp.load_source('passenger_wsgi', startup_file)
App 2146154 output: File "/home/yutijjfa/virtualenv/public_html/app/webroot/pybot/3.8/lib64/python3.8/imp.py", line 171, in load_source
App 2146154 output: module = _load(spec)
App 2146154 output: File "", line 702, in _load
App 2146154 output: File "", line 671, in _load_unlocked
App 2146154 output: File "", line 783, in exec_module
App 2146154 output: File "", line 219, in _call_with_frames_removed
App 2146154 output: File "/home/yutijjfa/public_html/app/webroot/pybot/passenger_wsgi.py", line 9, in
App 2146154 output: application = wsgi.app
App 2146154 output: AttributeError: module 'wsgi' has no attribute 'app'
Hello everyone, i keep getting this issue:
from .models import Post, User
ImportError: attempted relative import with no known parent package
I would appreciate it if anyone could help.
could somebody help me please.
After testing the finished product I have noticed that when you make more than one post the website says that you do not have permission to delete the second post
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.