Wireup: Dependency Injection for Flask
https://github.com/maldoinc/wireup
/r/flask
https://redd.it/183vbsn
https://github.com/maldoinc/wireup
/r/flask
https://redd.it/183vbsn
GitHub
GitHub - maldoinc/wireup: Performant, concise, and easy-to-use dependency injection container for Python 3.8+.
Performant, concise, and easy-to-use dependency injection container for Python 3.8+. - maldoinc/wireup
The Python Rich Package: Unleash the Power of Console Text
https://realpython.com/python-rich-package/
/r/Python
https://redd.it/185xcm7
https://realpython.com/python-rich-package/
/r/Python
https://redd.it/185xcm7
Realpython
The Python Rich Package: Unleash the Power of Console Text – Real Python
Rich is a powerful library for constructing text-based user interfaces (TUIs) using Python. With it, you can make your code more readable by pretty-printing complex data structures, and you can make your app more attractive for your user with colored and…
Deploy Flask-app on IIS?
Hi all,
I have a simple Flask-app with the following structure that works fine locally on my machine:
\- app.py
\- static (folder)
\- scripts.js
\- styles.css
\- templates (folder)
\-index.html
app.py looks like this:
from flask import Flask, render_template
app = Flask(__name__)
# Ensure templates are auto-reloaded
app.config["TEMPLATES_AUTO_RELOAD"] = True
# Define the index page
@app.route("/", methods=["GET"])
def index():
resources = ['listhere']
instances = list(range(1,100))
# Add leading zero to first 10 digits
for i in range(9):
instances[i] = "0" + str(i + 1)
# Sort all lists just in case
resources = sorted(resources)
locations =
/r/flask
https://redd.it/185zp24
Hi all,
I have a simple Flask-app with the following structure that works fine locally on my machine:
\- app.py
\- static (folder)
\- scripts.js
\- styles.css
\- templates (folder)
\-index.html
app.py looks like this:
from flask import Flask, render_template
app = Flask(__name__)
# Ensure templates are auto-reloaded
app.config["TEMPLATES_AUTO_RELOAD"] = True
# Define the index page
@app.route("/", methods=["GET"])
def index():
resources = ['listhere']
instances = list(range(1,100))
# Add leading zero to first 10 digits
for i in range(9):
instances[i] = "0" + str(i + 1)
# Sort all lists just in case
resources = sorted(resources)
locations =
/r/flask
https://redd.it/185zp24
Reddit
From the flask community on Reddit: Deploy Flask-app on IIS?
Explore this post and more from the flask community
What are the best libraries to work with graphs?
The title says it all. I am working on a project involving some number theory and graphs.
What Python packages do you know that would make working with graphs the easiest? Perhaps SageMath?
/r/Python
https://redd.it/185xexg
The title says it all. I am working on a project involving some number theory and graphs.
What Python packages do you know that would make working with graphs the easiest? Perhaps SageMath?
/r/Python
https://redd.it/185xexg
Reddit
From the Python community on Reddit
Explore this post and more from the Python community
Just like in the real world, django also has F expressions. Quick tip
/r/django
https://redd.it/185rb8e
/r/django
https://redd.it/185rb8e
Django GraphDB
Hi everyone - never did a big Django project before but now I plan to start one which might grow in the future. It is an internal app and it will need to do some operations with Neo4j. My question is: is Django my best option or should I use another framework? I will need the basic admin over users etc but in terms of ""additional"" databases, I need to build a knowledge db with Neo4j (or any alternative graphdb). thanks in advance :)
/r/django
https://redd.it/185znuv
Hi everyone - never did a big Django project before but now I plan to start one which might grow in the future. It is an internal app and it will need to do some operations with Neo4j. My question is: is Django my best option or should I use another framework? I will need the basic admin over users etc but in terms of ""additional"" databases, I need to build a knowledge db with Neo4j (or any alternative graphdb). thanks in advance :)
/r/django
https://redd.it/185znuv
Reddit
From the django community on Reddit
Explore this post and more from the django community
pytest parametrize vs highly repetitive code?
In pytest ... or, for that matter, in the world of QA automation ... the coder is usually given the ability to parameterize variables that control the test cases. But at what point of adding successive parameters does this become overkill? What are your rules-of-thumb when deciding to write another test function or add a parameter (and perhaps an if-statement or more) to an existing test function?
I've always leaned toward the parameterize approach, only to, in the end, wish I hadn't made the primary test function so complicated and full of special-case if-statements. Having four or even eight nearly-identical test functions goes against the code-reuse theme that permeates s/w engineering. But sometimes code repetition is both easier to read and maintain - particularly in the domain of writing test automation.
/r/Python
https://redd.it/1866gj0
In pytest ... or, for that matter, in the world of QA automation ... the coder is usually given the ability to parameterize variables that control the test cases. But at what point of adding successive parameters does this become overkill? What are your rules-of-thumb when deciding to write another test function or add a parameter (and perhaps an if-statement or more) to an existing test function?
I've always leaned toward the parameterize approach, only to, in the end, wish I hadn't made the primary test function so complicated and full of special-case if-statements. Having four or even eight nearly-identical test functions goes against the code-reuse theme that permeates s/w engineering. But sometimes code repetition is both easier to read and maintain - particularly in the domain of writing test automation.
/r/Python
https://redd.it/1866gj0
Reddit
From the Python community on Reddit
Explore this post and more from the Python community
Which one is preferred: self.state.adding VS not self.pk?
I'm going to do some checks before object is saved in DB and I just came across this:
if self.state.adding: # do something
which I never used before. I only used:
if not self.pk: # do something
are they functionally equivalent for identifying new model instances? Does one method have advantages over the other in certain scenarios? Seeking insights on best practices and functional differences, if any.
Which one is preferred generally?
​
/r/django
https://redd.it/1867jpf
I'm going to do some checks before object is saved in DB and I just came across this:
if self.state.adding: # do something
which I never used before. I only used:
if not self.pk: # do something
are they functionally equivalent for identifying new model instances? Does one method have advantages over the other in certain scenarios? Seeking insights on best practices and functional differences, if any.
Which one is preferred generally?
​
/r/django
https://redd.it/1867jpf
Reddit
From the django community on Reddit
Explore this post and more from the django community
Wednesday Daily Thread: Beginner questions
# Weekly Thread: Beginner Questions 🐍
Welcome to our Beginner Questions thread! Whether you're new to Python or just looking to clarify some basics, this is the thread for you.
## How it Works:
1. Ask Anything: Feel free to ask any Python-related question. There are no bad questions here!
2. Community Support: Get answers and advice from the community.
3. Resource Sharing: Discover tutorials, articles, and beginner-friendly resources.
## Guidelines:
This thread is specifically for beginner questions. For more advanced queries, check out our [Advanced Questions Thread](#advanced-questions-thread-link).
## Recommended Resources:
If you don't receive a response, consider exploring r/LearnPython or join the Python Discord Server for quicker assistance.
## Example Questions:
1. What is the difference between a list and a tuple?
2. How do I read a CSV file in Python?
3. What are Python decorators and how do I use them?
4. How do I install a Python package using pip?
5. What is a virtual environment and why should I use one?
Let's help each other learn Python! 🌟
/r/Python
https://redd.it/186b1u1
# Weekly Thread: Beginner Questions 🐍
Welcome to our Beginner Questions thread! Whether you're new to Python or just looking to clarify some basics, this is the thread for you.
## How it Works:
1. Ask Anything: Feel free to ask any Python-related question. There are no bad questions here!
2. Community Support: Get answers and advice from the community.
3. Resource Sharing: Discover tutorials, articles, and beginner-friendly resources.
## Guidelines:
This thread is specifically for beginner questions. For more advanced queries, check out our [Advanced Questions Thread](#advanced-questions-thread-link).
## Recommended Resources:
If you don't receive a response, consider exploring r/LearnPython or join the Python Discord Server for quicker assistance.
## Example Questions:
1. What is the difference between a list and a tuple?
2. How do I read a CSV file in Python?
3. What are Python decorators and how do I use them?
4. How do I install a Python package using pip?
5. What is a virtual environment and why should I use one?
Let's help each other learn Python! 🌟
/r/Python
https://redd.it/186b1u1
Discord
Join the Python Discord Server!
We're a large community focused around the Python programming language. We believe that anyone can learn to code. | 412982 members
How to configure django-markdown-editor to save upload images to local storage
Hi there,
Here is what is working:
* Create an new Django app, installed & configure with django markdown editor ([https://pypi.org/project/martor/](https://pypi.org/project/martor/)). register the application at [https://api.imgur.com/oauth2/addclient](https://api.imgur.com/oauth2/addclient) to get IMGUR\_CLIENT\_ID & IMGUR\_API\_KEY. It is working with no issue when uploading image but it saves to imgur's website ([https://i.imgur.com/dqHGHXp.jpg](https://i.imgur.com/dqHGHXp.jpg))
​
Here is not working:
I tried to configure & save the uploaded images to local storage based on it's wiki but it does NOT work
[https://github.com/agusmakmun/django-markdown-editor/wiki](https://github.com/agusmakmun/django-markdown-editor/wiki)
I have the following in my app's [urls.py](https://urls.py) but it never call "markdown\_uploader" function
\# [urls.py](https://urls.py)
urlpatterns = \[path('api/uploader/', markdown\_uploader, name='markdown\_uploader\_page'),\]
\# [views.py](https://views.py)
\# @ login\_requireddef markdown\_uploader(request):
print("got here???")
....
Has anyone able to save the upload images to either local storage or AWS S3?
​
/r/django
https://redd.it/186bx4o
Hi there,
Here is what is working:
* Create an new Django app, installed & configure with django markdown editor ([https://pypi.org/project/martor/](https://pypi.org/project/martor/)). register the application at [https://api.imgur.com/oauth2/addclient](https://api.imgur.com/oauth2/addclient) to get IMGUR\_CLIENT\_ID & IMGUR\_API\_KEY. It is working with no issue when uploading image but it saves to imgur's website ([https://i.imgur.com/dqHGHXp.jpg](https://i.imgur.com/dqHGHXp.jpg))
​
Here is not working:
I tried to configure & save the uploaded images to local storage based on it's wiki but it does NOT work
[https://github.com/agusmakmun/django-markdown-editor/wiki](https://github.com/agusmakmun/django-markdown-editor/wiki)
I have the following in my app's [urls.py](https://urls.py) but it never call "markdown\_uploader" function
\# [urls.py](https://urls.py)
urlpatterns = \[path('api/uploader/', markdown\_uploader, name='markdown\_uploader\_page'),\]
\# [views.py](https://views.py)
\# @ login\_requireddef markdown\_uploader(request):
print("got here???")
....
Has anyone able to save the upload images to either local storage or AWS S3?
​
/r/django
https://redd.it/186bx4o
PyPI
martor
Django Markdown Editor
What's up Python? New args syntax, subinterpreters FastAPI and cuda pandas…
https://www.bitecode.dev/p/whats-up-python-new-args-syntax-subinterpreters
/r/Python
https://redd.it/18676xd
https://www.bitecode.dev/p/whats-up-python-new-args-syntax-subinterpreters
/r/Python
https://redd.it/18676xd
www.bitecode.dev
What's up Python? New args syntax, subinterpreters FastAPI and cuda pandas…
October 2023
htmx or basic javascript?
almost finished a js course, and want to dive into learning django. was thinking of doing react until I found out about htmx. Here's the thing, can I skip htmx completely and just focus on basic js, since from some of the posts on this sub I hear that while htmx is great its not comprehensive like js. so if i've already invested time in js, can I just focus on that as everything htmx can do - js can do, but everything js can do - htmx can't do?
really knew to this stuff, dont want to invest time in something that i don't need.
thanks for reading
/r/django
https://redd.it/186gtej
almost finished a js course, and want to dive into learning django. was thinking of doing react until I found out about htmx. Here's the thing, can I skip htmx completely and just focus on basic js, since from some of the posts on this sub I hear that while htmx is great its not comprehensive like js. so if i've already invested time in js, can I just focus on that as everything htmx can do - js can do, but everything js can do - htmx can't do?
really knew to this stuff, dont want to invest time in something that i don't need.
thanks for reading
/r/django
https://redd.it/186gtej
Reddit
From the django community on Reddit
Explore this post and more from the django community
Flask-Muck: Flask REST Framework that generates complete CRUD APIs for your SqlAlchemy models in as little as 9 lines of code.
"With Flask-Muck you don't have to worry about the CRUD.
Flask-Muck is a batteries-included framework for automatically generating RESTful APIs with Create, Read, Update and Delete (CRUD) endpoints in a Flask/SqlAlchemy application stack."
Links: GitHub \- Documentation \- PyPi
​
After years of working in Flask/SqlAlchemy/Marshmallow apps I felt like there was a large gap in the tooling for creating standard REST APIs that perform basic CRUD operations. Especially when comparing it to the Django ecosystem. I'm hoping this can remove large amounts of boilerplate for folks and get some projects bootstrapped and off the ground much more quickly.
The library has just been released so I'm leaving the beta tag on the pypi releases for a bit until I get some strong feedback. I'm currently looking for early adopters to use it in personal/side projects.
If anyone would like to take it for a spin and report back on any missing features or bugs I'd love to work with you. I don't have much to offer but would be happy to credit you as a contributor to the project.
​
/r/Python
https://redd.it/186k0td
"With Flask-Muck you don't have to worry about the CRUD.
Flask-Muck is a batteries-included framework for automatically generating RESTful APIs with Create, Read, Update and Delete (CRUD) endpoints in a Flask/SqlAlchemy application stack."
Links: GitHub \- Documentation \- PyPi
​
After years of working in Flask/SqlAlchemy/Marshmallow apps I felt like there was a large gap in the tooling for creating standard REST APIs that perform basic CRUD operations. Especially when comparing it to the Django ecosystem. I'm hoping this can remove large amounts of boilerplate for folks and get some projects bootstrapped and off the ground much more quickly.
The library has just been released so I'm leaving the beta tag on the pypi releases for a bit until I get some strong feedback. I'm currently looking for early adopters to use it in personal/side projects.
If anyone would like to take it for a spin and report back on any missing features or bugs I'd love to work with you. I don't have much to offer but would be happy to credit you as a contributor to the project.
​
/r/Python
https://redd.it/186k0td
GitHub
GitHub - dtiesling/flask-muck at v0.0.3b6
🧹 Flask REST framework for generating CRUD APIs and OpenAPI specs in the SQLAlchemy, Marshmallow/Pydantic application stack. - GitHub - dtiesling/flask-muck at v0.0.3b6
Introducing drf-api-action : Empowering Django REST Framework with Enhanced Functionality
Hi all,
I created a project named drf-api-action which Obtains web framework benefits for making API Python packages
What is drf-api-action?
drf-api-action is an ingenious extension to the popular rest_framework package, introducing a decorator called api_action.
Building upon the foundation of the existing action decorator, this new addition transforms a REST API call in a class view into a straightforward function call.
With this decorator, you can effortlessly create an instance of the view and explicitly invoke its functions.
✨ Key Benefits:
1. Arguments Validation: Ensure the integrity of your API by effortlessly validating arguments.
2. Pagination: Seamlessly implement pagination within your API functions.
3. Clear Separation of Concerns: Enjoy a clean separation between function signature and business logic, enhancing code readability.
4. Database Model Accessibility: Easily access Django DB models in other libraries or web services.
And Many More! : drf-api-action opens the door to many advantages, making DRF even more versatile for your projects.
GitHub Repository: Check out the code on GitHub
Dive Deeper on Medium: Read the in-depth article on Medium
If you find drf-api-action beneficial for your projects, show your support by starring the GitHub repository. Your stars help us grow and motivate us to continue enhancing this powerful tool for the DRF community.
# #Django #RESTFramework
/r/django
https://redd.it/186o89g
Hi all,
I created a project named drf-api-action which Obtains web framework benefits for making API Python packages
What is drf-api-action?
drf-api-action is an ingenious extension to the popular rest_framework package, introducing a decorator called api_action.
Building upon the foundation of the existing action decorator, this new addition transforms a REST API call in a class view into a straightforward function call.
With this decorator, you can effortlessly create an instance of the view and explicitly invoke its functions.
✨ Key Benefits:
1. Arguments Validation: Ensure the integrity of your API by effortlessly validating arguments.
2. Pagination: Seamlessly implement pagination within your API functions.
3. Clear Separation of Concerns: Enjoy a clean separation between function signature and business logic, enhancing code readability.
4. Database Model Accessibility: Easily access Django DB models in other libraries or web services.
And Many More! : drf-api-action opens the door to many advantages, making DRF even more versatile for your projects.
GitHub Repository: Check out the code on GitHub
Dive Deeper on Medium: Read the in-depth article on Medium
If you find drf-api-action beneficial for your projects, show your support by starring the GitHub repository. Your stars help us grow and motivate us to continue enhancing this powerful tool for the DRF community.
# #Django #RESTFramework
/r/django
https://redd.it/186o89g
GitHub
GitHub - Ori-Roza/drf-api-action: drf-api-action elevates Django Rest Framework testing with the action_api fixture, simplifying…
drf-api-action elevates Django Rest Framework testing with the action_api fixture, simplifying REST endpoint testing to a seamless, function-like experience. - Ori-Roza/drf-api-action
Native PyPI support in Pixi (conda package manager written in Rust)
https://prefix.dev/blog/pypi_support_in_pixi
/r/Python
https://redd.it/186rp72
https://prefix.dev/blog/pypi_support_in_pixi
/r/Python
https://redd.it/186rp72
prefix.dev
Unleashing PyPI support in pixi
We've deeply integrated PyPI packages into pixi.toml's - read more ...
Materio - Bootstrap Django Admin Dashboard Template
Hello Everyone,
I would like to share a brand new [Materio Bootstrap 5 Django Admin Template](https://themeselection.com/item/materio-bootstrap-django-admin-template/). It provides 10 useful applications like email, chat, academy, logistics, etc. that enable you to get started and build your applications faster. Besides, it also comes with 75+ Basic and advanced Cards for eCommerce Analytics, CRM, Statistics, and Interactive Charts.
Additionally, Materio Django Admin Dashboard has 15+ Front pages including a dedicated landing page and other most commonly used pages, saving you time and effort in launching your app.
Create eye-catching, high-quality, and responsive web applications with ease.
**Features:**
* Built with **Django 4**
* Using CSS Framework **Bootstrap 5.3.2**
* **CRUD Example**
* **Docker** for Faster Development
* **Vertical and horizontal** layouts
* Default, Bordered & Semi-dark themes
* **Light, Dark, and system** mode support
* Internationalization/i18n & RTL Ready
* **Python-Dotenv:** Environment variables
* Theme Config
* **5 Dashboard**
* **10 Pre-Built Apps**
* **15+ Front Pages &** Much more....!!
Hope you all like it.
Feel free to provide you
/r/django
https://redd.it/186ofvp
Hello Everyone,
I would like to share a brand new [Materio Bootstrap 5 Django Admin Template](https://themeselection.com/item/materio-bootstrap-django-admin-template/). It provides 10 useful applications like email, chat, academy, logistics, etc. that enable you to get started and build your applications faster. Besides, it also comes with 75+ Basic and advanced Cards for eCommerce Analytics, CRM, Statistics, and Interactive Charts.
Additionally, Materio Django Admin Dashboard has 15+ Front pages including a dedicated landing page and other most commonly used pages, saving you time and effort in launching your app.
Create eye-catching, high-quality, and responsive web applications with ease.
**Features:**
* Built with **Django 4**
* Using CSS Framework **Bootstrap 5.3.2**
* **CRUD Example**
* **Docker** for Faster Development
* **Vertical and horizontal** layouts
* Default, Bordered & Semi-dark themes
* **Light, Dark, and system** mode support
* Internationalization/i18n & RTL Ready
* **Python-Dotenv:** Environment variables
* Theme Config
* **5 Dashboard**
* **10 Pre-Built Apps**
* **15+ Front Pages &** Much more....!!
Hope you all like it.
Feel free to provide you
/r/django
https://redd.it/186ofvp
ThemeSelection
Materio Dashboard PRO - Django 5
Build responsive web apps easily with Materio Dashboard PRO - Django 5. Best Django admin with basic CRUD functionality & role-based auth.
Python scripts for FanDuel and DraftKings
Anyone interested in helping making code for gambling sites I been in contract with Sportradar it’s a company that keeps track of nba stats and data so you’ll get pace of play, player usage, player points, rebounds, assist etc
/r/Python
https://redd.it/18704rx
Anyone interested in helping making code for gambling sites I been in contract with Sportradar it’s a company that keeps track of nba stats and data so you’ll get pace of play, player usage, player points, rebounds, assist etc
/r/Python
https://redd.it/18704rx
Reddit
From the Python community on Reddit
Explore this post and more from the Python community
Thursday Daily Thread: Python Careers, Courses, and Furthering Education!
# Weekly Thread: Professional Use, Jobs, and Education 🏢
Welcome to this week's discussion on Python in the professional world! This is your spot to talk about job hunting, career growth, and educational resources in Python. Please note, this thread is not for recruitment.
---
## How it Works:
1. Career Talk: Discuss using Python in your job, or the job market for Python roles.
2. Education Q&A: Ask or answer questions about Python courses, certifications, and educational resources.
3. Workplace Chat: Share your experiences, challenges, or success stories about using Python professionally.
---
## Guidelines:
- This thread is not for recruitment. For job postings, please see r/PythonJobs or the recruitment thread in the sidebar.
- Keep discussions relevant to Python in the professional and educational context.
---
## Example Topics:
1. Career Paths: What kinds of roles are out there for Python developers?
2. Certifications: Are Python certifications worth it?
3. Course Recommendations: Any good advanced Python courses to recommend?
4. Workplace Tools: What Python libraries are indispensable in your professional work?
5. Interview Tips: What types of Python questions are commonly asked in interviews?
---
Let's help each other grow in our careers and education. Happy discussing! 🌟
/r/Python
https://redd.it/18744bp
# Weekly Thread: Professional Use, Jobs, and Education 🏢
Welcome to this week's discussion on Python in the professional world! This is your spot to talk about job hunting, career growth, and educational resources in Python. Please note, this thread is not for recruitment.
---
## How it Works:
1. Career Talk: Discuss using Python in your job, or the job market for Python roles.
2. Education Q&A: Ask or answer questions about Python courses, certifications, and educational resources.
3. Workplace Chat: Share your experiences, challenges, or success stories about using Python professionally.
---
## Guidelines:
- This thread is not for recruitment. For job postings, please see r/PythonJobs or the recruitment thread in the sidebar.
- Keep discussions relevant to Python in the professional and educational context.
---
## Example Topics:
1. Career Paths: What kinds of roles are out there for Python developers?
2. Certifications: Are Python certifications worth it?
3. Course Recommendations: Any good advanced Python courses to recommend?
4. Workplace Tools: What Python libraries are indispensable in your professional work?
5. Interview Tips: What types of Python questions are commonly asked in interviews?
---
Let's help each other grow in our careers and education. Happy discussing! 🌟
/r/Python
https://redd.it/18744bp
Reddit
From the Python community on Reddit
Explore this post and more from the Python community
I made a tool that generates template for you typed function like golang
https://x.com/RomanMatweenko/status/1729872546483642456?s=20
Suppose you've got a simple \#python function with types typed in. It'd be cool to have a tool that can generate test templates based on the types, right, like GOlang can? That's what this project about
original function we want to generate test template
simple result
VScode extension https://github.com/RomanMIzulin/python\_unittest\_vscode can be found in market by unittest_generator
/r/Python
https://redd.it/186r0gt
https://x.com/RomanMatweenko/status/1729872546483642456?s=20
Suppose you've got a simple \#python function with types typed in. It'd be cool to have a tool that can generate test templates based on the types, right, like GOlang can? That's what this project about
original function we want to generate test template
simple result
VScode extension https://github.com/RomanMIzulin/python\_unittest\_vscode can be found in market by unittest_generator
/r/Python
https://redd.it/186r0gt
X (formerly Twitter)
Роман Матвеенко (@RomanMatweenko) on X
Suppose you've got a simple #python function with types typed in. It'd be cool to have a tool that can generate test templates based on the types, right, like GOlang can? That's what this project about https://t.co/ZY5oSAKVvJ
I Have no Idea what to do
from flask import Flask, request, current_app, redirect, render_template, url_for, session, flash
from edit_form import NewForm, EditForm
app = Flask(__name__)
app.config['SECRET_KEY'] = '48a89ef0b9a63e63dc8a5ca21fc1871d'
blog = [{'id':1, 'author':'Tai', 'title': 'First post', 'content':'This is the content of post 1'},
{'id':2, 'author':'Kay', 'title': 'Second post', 'content':'This is the content of post 2'}]
@app.route('/', methods = ['POST','GET'] )
def index():
return render_template('homepage.html', blog_dic=blog)
@app.route('/post/<int:post_id>')
def post(post_id):
selected_post = next(( i for i in blog if i['id'] == post_id), None)
if selected_post:
return render_template('actual_blog_post.html', blog_dic=blog, detail_2=selected_post)
else:
return 'Post not found', 404
@app.route('/post/new_post', methods = ['POST','GET'] )
def new_post():
blog_add = {}
nw_post = NewForm()
if nw_post.validate_on_submit():
blog_add = {
'id': len(blog) + 1,
'author': nw_post.author.data,
'title': nw_post.title.data,
'content': nw_post.new_post.data
/r/flask
https://redd.it/1872zqr
from flask import Flask, request, current_app, redirect, render_template, url_for, session, flash
from edit_form import NewForm, EditForm
app = Flask(__name__)
app.config['SECRET_KEY'] = '48a89ef0b9a63e63dc8a5ca21fc1871d'
blog = [{'id':1, 'author':'Tai', 'title': 'First post', 'content':'This is the content of post 1'},
{'id':2, 'author':'Kay', 'title': 'Second post', 'content':'This is the content of post 2'}]
@app.route('/', methods = ['POST','GET'] )
def index():
return render_template('homepage.html', blog_dic=blog)
@app.route('/post/<int:post_id>')
def post(post_id):
selected_post = next(( i for i in blog if i['id'] == post_id), None)
if selected_post:
return render_template('actual_blog_post.html', blog_dic=blog, detail_2=selected_post)
else:
return 'Post not found', 404
@app.route('/post/new_post', methods = ['POST','GET'] )
def new_post():
blog_add = {}
nw_post = NewForm()
if nw_post.validate_on_submit():
blog_add = {
'id': len(blog) + 1,
'author': nw_post.author.data,
'title': nw_post.title.data,
'content': nw_post.new_post.data
/r/flask
https://redd.it/1872zqr
Reddit
From the flask community on Reddit
Explore this post and more from the flask community