Flask run fail after Python update
I updated my Python from version 3.9.2 to 3.11.1 on a Windows 10 machine. I reinstalled Flask and other modules I needed for the new Python version through pip and it seems that my apps work as normal when I use
One think I have noticed, but I have no idea if this relevant or not, is that the old Python was installed under C:\\Program Files while the new one is only installed in AppData/Local even though I installed it for all Users. Plus I can't change the installation path in the setup program, even when running it as Administrator.
/r/flask
https://redd.it/1002wun
I updated my Python from version 3.9.2 to 3.11.1 on a Windows 10 machine. I reinstalled Flask and other modules I needed for the new Python version through pip and it seems that my apps work as normal when I use
python -m flask run. However just flask run still looks for the old (and now uninstalled) Python 3.9 and of course fails as the system can't find the files. How can I fix this? I tried uninstalling it and reinstalling it with no success. One think I have noticed, but I have no idea if this relevant or not, is that the old Python was installed under C:\\Program Files while the new one is only installed in AppData/Local even though I installed it for all Users. Plus I can't change the installation path in the setup program, even when running it as Administrator.
/r/flask
https://redd.it/1002wun
reddit
Flask run fail after Python update
I updated my Python from version 3.9.2 to 3.11.1 on a Windows 10 machine. I reinstalled Flask and other modules I needed for the new Python...
Operational error after changing the operating system
Dear Flask developers,
\-I built my flask app on WSL(Windows Subsystem for Linux) without a problem and it is working on WSL.
\-In order to test my app on a server environment I copied my app to an OpenBSD virtual machine on Hyper-V.
\-Ran my app on the local network.
\-I tried to connect from a different machine to the server(OpenBSD VM). Connected without a problem.
\-There is a login screen in my app and when I try to login as a user I got an operational error:
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: Users
SQL: SELECT "Users".id AS "Users_id", "Users".email AS "Users_email", "Users".password AS "Users_password", "Users".option_1 AS "Users_option_1", "Users".option_2 AS "Users_option_2", "Users".option_3 AS "Users_option_3"
FROM "Users"
WHERE "Users".email = ?
LIMIT ? OFFSET ?
parameters: ('test_1@test.com', 1, 0)
(Background on this error at: https://sqlalche.me/e/14/e3q8)
​
Traceback (most recent call last)
File "/home/user/.local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1900, in executecontext
self.dialect.doexecute(
File "/home/user/.local/lib/python3.9/site-packages/sqlalchemy/engine/default.py", line 736, in doexecute
cursor.execute(statement, parameters)
Could
/r/flask
https://redd.it/zzuv8x
Dear Flask developers,
\-I built my flask app on WSL(Windows Subsystem for Linux) without a problem and it is working on WSL.
\-In order to test my app on a server environment I copied my app to an OpenBSD virtual machine on Hyper-V.
\-Ran my app on the local network.
\-I tried to connect from a different machine to the server(OpenBSD VM). Connected without a problem.
\-There is a login screen in my app and when I try to login as a user I got an operational error:
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: Users
SQL: SELECT "Users".id AS "Users_id", "Users".email AS "Users_email", "Users".password AS "Users_password", "Users".option_1 AS "Users_option_1", "Users".option_2 AS "Users_option_2", "Users".option_3 AS "Users_option_3"
FROM "Users"
WHERE "Users".email = ?
LIMIT ? OFFSET ?
parameters: ('test_1@test.com', 1, 0)
(Background on this error at: https://sqlalche.me/e/14/e3q8)
​
Traceback (most recent call last)
File "/home/user/.local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1900, in executecontext
self.dialect.doexecute(
File "/home/user/.local/lib/python3.9/site-packages/sqlalchemy/engine/default.py", line 736, in doexecute
cursor.execute(statement, parameters)
Could
/r/flask
https://redd.it/zzuv8x
reddit
Operational error after changing the operating system
Dear Flask developers, \-I built my flask app on WSL(Windows Subsystem for Linux) without a problem and it is working on WSL. \-In order to test...
Deploying an application to “production” in AWA
I have a Django app. I totally messed up it’s configuration and I can’t get it running. Honestly, I have no idea how I got in running in the first place a year ago. I’m not comfortable at all with Apache etc.
I’d like to reset it up from scratch. Are there any great, detailed tutorials. I need to use my custom domain and SSL as well.
Please help :)
/r/django
https://redd.it/1006r4u
I have a Django app. I totally messed up it’s configuration and I can’t get it running. Honestly, I have no idea how I got in running in the first place a year ago. I’m not comfortable at all with Apache etc.
I’d like to reset it up from scratch. Are there any great, detailed tutorials. I need to use my custom domain and SSL as well.
Please help :)
/r/django
https://redd.it/1006r4u
reddit
Deploying an application to “production” in AWA
I have a Django app. I totally messed up it’s configuration and I can’t get it running. Honestly, I have no idea how I got in running in the first...
Sunday Daily Thread: What's everyone working on this week?
Tell /r/python what you're working on this week! You can be bragging, grousing, sharing your passion, or explaining your pain. Talk about your current project or your pet project; whatever you want to share.
/r/Python
https://redd.it/10073zi
Tell /r/python what you're working on this week! You can be bragging, grousing, sharing your passion, or explaining your pain. Talk about your current project or your pet project; whatever you want to share.
/r/Python
https://redd.it/10073zi
Reddit
r/Python on Reddit: Sunday Daily Thread: What's everyone working on this week?
Posted by u/Im__Joseph - 5 votes and 22 comments
Is it possible to set the USERNAME_FIELD to email without having to build a custom manager and forms from scratch?
Im trying to setup a user model with an added birthday field and remove the username field. Can I do this using the usercreation forms and built in manager? Or would I still have to create my own from scratch
/r/djangolearning
https://redd.it/100ai5k
Im trying to setup a user model with an added birthday field and remove the username field. Can I do this using the usercreation forms and built in manager? Or would I still have to create my own from scratch
/r/djangolearning
https://redd.it/100ai5k
reddit
Is it possible to set the USERNAME_FIELD to email without having...
Im trying to setup a user model with an added birthday field and remove the username field. Can I do this using the usercreation forms and built...
Creating a webp image on post_save
Hi everyone,
I've figured out how to create a webp image in my /media/ folder within the correct directory. Now, I'm needing to save this image to a field that i've crated on my model.
def create_webp_image(sender, instance, *args, **kwargs):
image_url = instance.image.thumbnail['1920x1080'].url
path = "http://localhost:8000" + image_url
response = requests.get(path, stream=True)
img = Image.open(BytesIO(response.content))
#build filepath
position = path.rfind("/") + 1
newpath2 = path[0:position].split('/media/')[1]
#get name of file (eg. picture.webp)
name_of_file = path[position:].split('.')[0] + ".webp"
#get directory
image_dir = os.path.join(settings.MEDIA_ROOT, '')
/r/django
https://redd.it/1005ij1
Hi everyone,
I've figured out how to create a webp image in my /media/ folder within the correct directory. Now, I'm needing to save this image to a field that i've crated on my model.
def create_webp_image(sender, instance, *args, **kwargs):
image_url = instance.image.thumbnail['1920x1080'].url
path = "http://localhost:8000" + image_url
response = requests.get(path, stream=True)
img = Image.open(BytesIO(response.content))
#build filepath
position = path.rfind("/") + 1
newpath2 = path[0:position].split('/media/')[1]
#get name of file (eg. picture.webp)
name_of_file = path[position:].split('.')[0] + ".webp"
#get directory
image_dir = os.path.join(settings.MEDIA_ROOT, '')
/r/django
https://redd.it/1005ij1
reddit
Creating a webp image on post_save
Hi everyone, I've figured out how to create a webp image in my /media/ folder within the correct directory. Now, I'm needing to save this image...
Workaround ALLOWED_HOSTS for a specific route for startup probe?
I am deploying a Django app to a kubernetes cluster. I want it to have a startup probe, which will basically just be a view that checks the database connection and returns a 200 response.
I'm having trouble because kubernetes will make a request directly to the pod IP with the pods hostname. Additionally, the kubernetes config is kind of out of my hands. I'd rather solve the problem by having a looser Django view than monkeying with the infrastructure code.
Is there a way for a single route / view to ignore the hosts whitelist?
/r/django
https://redd.it/1001y06
I am deploying a Django app to a kubernetes cluster. I want it to have a startup probe, which will basically just be a view that checks the database connection and returns a 200 response.
I'm having trouble because kubernetes will make a request directly to the pod IP with the pods hostname. Additionally, the kubernetes config is kind of out of my hands. I'd rather solve the problem by having a looser Django view than monkeying with the infrastructure code.
Is there a way for a single route / view to ignore the hosts whitelist?
/r/django
https://redd.it/1001y06
reddit
Workaround ALLOWED_HOSTS for a specific route for startup probe?
I am deploying a Django app to a kubernetes cluster. I want it to have a startup probe, which will basically just be a view that checks the...
connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL: role "rootuser" does not exist
\`I am trying to connect deploy a django backend with postgres db on digitalocean droplet. but it's giving me this error after after gunicorn and nginx setup:
`connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL: role "rootuser" does not exist`
rootuser is my root username not the db username, my db username is dbadmin
i tried to create db user with name serveroot, it worked but started throwing other errors
`\`relation "django_site" does not exist LINE 1: ..."django_site"."domain", "django_site"."name" FROM "django_si...`
/r/django
https://redd.it/zyze4t
\`I am trying to connect deploy a django backend with postgres db on digitalocean droplet. but it's giving me this error after after gunicorn and nginx setup:
`connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL: role "rootuser" does not exist`
rootuser is my root username not the db username, my db username is dbadmin
i tried to create db user with name serveroot, it worked but started throwing other errors
`\`relation "django_site" does not exist LINE 1: ..."django_site"."domain", "django_site"."name" FROM "django_si...`
/r/django
https://redd.it/zyze4t
reddit
connection to server on socket "/var/run/postgresql/.s.PGSQL.5432"...
\`I am trying to connect deploy a django backend with postgres db on digitalocean droplet. but it's giving me this error after after gunicorn and...
Quick wins in improving your Python codebase health
https://www.rockandnull.com/python-code-formatter/
/r/djangolearning
https://redd.it/zzsjvx
https://www.rockandnull.com/python-code-formatter/
/r/djangolearning
https://redd.it/zzsjvx
Rock and Null
Quick wins in improving your Python codebase health
There are countless ways to keep your Python as tidy and readable as possible. Here, I aim to cover the easiest yet most impactful ways to do that in your Python codebase.
Count the Comment ID over again when created in different Post
Hello!
I would like to know if it possible and if it is, how make the ID of the Comment to start to count over again when created in a different Post.
Thank you!
Models:
class Post(models.Model):
title = models.CharField(max_length=100)
content = models.TextField()
author = models.ForeignKey(User, on_delete=models.CASCADE)
def get_absolute_url(self):
return reverse('post-detail', kwargs={'pk': self.pk })
class Comment(models.Model):
post = models.ForeignKey(Post,related_name='comments', on_delete=models.CASCADE)
content = models.TextField()
author = models.ForeignKey(User, on_delete=models.CASCADE)
/r/djangolearning
https://redd.it/100irg7
Hello!
I would like to know if it possible and if it is, how make the ID of the Comment to start to count over again when created in a different Post.
Thank you!
Models:
class Post(models.Model):
title = models.CharField(max_length=100)
content = models.TextField()
author = models.ForeignKey(User, on_delete=models.CASCADE)
def get_absolute_url(self):
return reverse('post-detail', kwargs={'pk': self.pk })
class Comment(models.Model):
post = models.ForeignKey(Post,related_name='comments', on_delete=models.CASCADE)
content = models.TextField()
author = models.ForeignKey(User, on_delete=models.CASCADE)
/r/djangolearning
https://redd.it/100irg7
reddit
Count the Comment ID over again when created in different Post
Hello! I would like to know if it possible and if it is, how make the ID of the Comment to start to count over again when created in a different...
Monday Daily Thread: Project ideas!
Comment any project ideas beginner or advanced in this thread for others to give a try! If you complete one make sure to reply to the comment with how you found it and attach some source code! If you're looking for project ideas, you might be interested in checking out Al Sweigart's, "The Big Book of Small Python Projects" which provides a list of projects and the code to make them work.
/r/Python
https://redd.it/100xk64
Comment any project ideas beginner or advanced in this thread for others to give a try! If you complete one make sure to reply to the comment with how you found it and attach some source code! If you're looking for project ideas, you might be interested in checking out Al Sweigart's, "The Big Book of Small Python Projects" which provides a list of projects and the code to make them work.
/r/Python
https://redd.it/100xk64
reddit
Monday Daily Thread: Project ideas!
Comment any project ideas beginner or advanced in this thread for others to give a try! If you complete one make sure to reply to the comment with...
Can you (developers who've worked professionally with Djano) share a Django project Dockerfile and docker-compose files with what you consider best practices?
It'd be helpful for beginners like myself. I'm just starting out and I read conflicting opinions online about things like whether to include a python virtual environment within Docker or not, as well as about whether to create a new non-root user within the Docker environment or to leave it as root.
I'm also not sure about how to handle environment variables. Do I include them in an .env file and add it to .dockerignore and to .gitignore or do I export them to the system's shell and forgo the .env file?
The samples I've found online describe themselves as quick start guides which leaves me unsure about points like what I've mentioned above. My project will include Django (DRF), Postgres, Celery, and Redis.
/r/django
https://redd.it/100qlts
It'd be helpful for beginners like myself. I'm just starting out and I read conflicting opinions online about things like whether to include a python virtual environment within Docker or not, as well as about whether to create a new non-root user within the Docker environment or to leave it as root.
I'm also not sure about how to handle environment variables. Do I include them in an .env file and add it to .dockerignore and to .gitignore or do I export them to the system's shell and forgo the .env file?
The samples I've found online describe themselves as quick start guides which leaves me unsure about points like what I've mentioned above. My project will include Django (DRF), Postgres, Celery, and Redis.
/r/django
https://redd.it/100qlts
reddit
Can you (developers who've worked professionally with Djano) share...
It'd be helpful for beginners like myself. I'm just starting out and I read conflicting opinions online about things like whether to include a...
9 Python Built-In Decorators That Optimize Your Code Significantly
https://medium.com/techtofreedom/9-python-built-in-decorators-that-optimize-your-code-significantly-bc3f661e9017
/r/flask
https://redd.it/100wqao
https://medium.com/techtofreedom/9-python-built-in-decorators-that-optimize-your-code-significantly-bc3f661e9017
/r/flask
https://redd.it/100wqao
Medium
9 Python Built-In Decorators That Optimize Your Code Significantly
Do more by less: leverage the power of decorators
How do I debug a exit-code failure for the specific service for my app?
I'm trying to run a Flask app through Apache and eventually host using EC2. When I run
systemctl list-units --type=service
I see that the unit for this specific app, "SITENAME.service" has failed.
When I run
sudo systemctl status SITENAME.service
I get an error saying:
Loaded: loaded (/etc/systemd/system/SITENAMEenv.service; enabled; vendor preset: enabled) Active: failed (Result: exit-code) since Sun 2023-01-01 21:26:25 UTC; 1min 1s ago Process: 787 ExecStart=/home/ubuntu/SITENAME/SITENAMEenv/bin/uwsgi --ini SITENAMEenv.ini (code=exited, status=1/FAILURE) Main PID: 787 (code=exited, status=1/FAILURE) Jan 01 21:26:25 ip-172-31-88-10 systemd1: SITENAME.service: Main process exited, code=exited, status=1/FAILURE Jan 01 21:26:25 ip-172-31-88-10 systemd1: SITENAME.service: Failed with result 'exit-code'.
Where can I get more information on this failure? I can't tell if this is a python issue in the actual application code, or something else.
/r/flask
https://redd.it/100xpkk
I'm trying to run a Flask app through Apache and eventually host using EC2. When I run
systemctl list-units --type=service
I see that the unit for this specific app, "SITENAME.service" has failed.
When I run
sudo systemctl status SITENAME.service
I get an error saying:
Loaded: loaded (/etc/systemd/system/SITENAMEenv.service; enabled; vendor preset: enabled) Active: failed (Result: exit-code) since Sun 2023-01-01 21:26:25 UTC; 1min 1s ago Process: 787 ExecStart=/home/ubuntu/SITENAME/SITENAMEenv/bin/uwsgi --ini SITENAMEenv.ini (code=exited, status=1/FAILURE) Main PID: 787 (code=exited, status=1/FAILURE) Jan 01 21:26:25 ip-172-31-88-10 systemd1: SITENAME.service: Main process exited, code=exited, status=1/FAILURE Jan 01 21:26:25 ip-172-31-88-10 systemd1: SITENAME.service: Failed with result 'exit-code'.
Where can I get more information on this failure? I can't tell if this is a python issue in the actual application code, or something else.
/r/flask
https://redd.it/100xpkk
reddit
How do I debug a exit-code failure for the specific service for my...
I'm trying to run a Flask app through Apache and eventually host using EC2. When I run systemctl list-units --type=service I see that the...
A Deep Dive into Heap and Heap Sort in Python: From Beginner to Expert
https://medium.com/techtofreedom/a-deep-dive-into-heap-and-heap-sort-in-python-from-beginner-to-expert-ae44f39a7d14
/r/flask
https://redd.it/100igyo
https://medium.com/techtofreedom/a-deep-dive-into-heap-and-heap-sort-in-python-from-beginner-to-expert-ae44f39a7d14
/r/flask
https://redd.it/100igyo
Medium
A Deep Dive into Heap and Heap Sort in Python: From Beginner to Expert
Master the heap and heap sort and take your Python skills to the next level
5 Uses of Lambda Functions in Python
https://medium.com/p/97c7c1a87244
/r/flask
https://redd.it/100n6lw
https://medium.com/p/97c7c1a87244
/r/flask
https://redd.it/100n6lw
Medium
5 Uses of Lambda Functions in Python
Use lambda functions to write your code elegantly
Nesting Blueprints with Blueprint.registerblueprint() fails
Even though the [Flask Docs](https://flask.palletsprojects.com/en/2.2.x/api/#flask.Blueprint.registerblueprint) state that a Blueprint can register further blueprints, I get the following error:
>AttributeError: 'Blueprint' object has no attribute 'register_blueprint'
Does someone know how I can achieve nesting blueprints?
Code
/r/flask
https://redd.it/100qn8a
Even though the [Flask Docs](https://flask.palletsprojects.com/en/2.2.x/api/#flask.Blueprint.registerblueprint) state that a Blueprint can register further blueprints, I get the following error:
>AttributeError: 'Blueprint' object has no attribute 'register_blueprint'
Does someone know how I can achieve nesting blueprints?
Code
/r/flask
https://redd.it/100qn8a
Django Authentication: The Basics With a Quick Tutorial
https://frontegg.com/django-authentication
/r/Python
https://redd.it/101chp8
https://frontegg.com/django-authentication
/r/Python
https://redd.it/101chp8
Frontegg
Django Authentication: The Basics With a Quick Tutorial | Frontegg
xplore Django's authentication system, including user creation, authentication, and permission setup, with a concise tutorial.
One to one relationship between user and another table.
I want to create another table that we'll call profile to put additional information about the user. I want to automatically create a profile for every user that will be created. That profile will, obviously, be attached to the user. My problem is I have almost no idea how to do that. I've heard that you could do it with signals but I have a feeling there is another, simpler way.
/r/djangolearning
https://redd.it/101od2g
I want to create another table that we'll call profile to put additional information about the user. I want to automatically create a profile for every user that will be created. That profile will, obviously, be attached to the user. My problem is I have almost no idea how to do that. I've heard that you could do it with signals but I have a feeling there is another, simpler way.
/r/djangolearning
https://redd.it/101od2g
reddit
One to one relationship between user and another table.
I want to create another table that we'll call profile to put additional information about the user. I want to automatically create a profile for...
Should you always use DRF when using Django as a backend for mobile apps?
I'm familiar building web apps with Django. I'm currently building a iOS app in Xcode (my first time building a mobile app) and since I know Django very well, I figured it makes sense to use Django as the backend for the iOS app.
I never had the need to use DRF (Django REST Framework) and never understood its uses when building web apps in Django. I just use javascript's Fetch API and ajax calls worked just fine.
After doing some research on using Django as a backend for mobile apps, it seems the general consensus is to use DRF to help build APIs for the mobile app. But I had some questions:
1. How advantageous is it to use DRF when using Django as a backend for iOS apps? Can't the iOS app just make a direct ajax call to a URL on the django server to get/post data?
2. Will using DRF cut down on development time? I'm not familiar with DRF so I will need to learn it first
/r/django
https://redd.it/101of7n
I'm familiar building web apps with Django. I'm currently building a iOS app in Xcode (my first time building a mobile app) and since I know Django very well, I figured it makes sense to use Django as the backend for the iOS app.
I never had the need to use DRF (Django REST Framework) and never understood its uses when building web apps in Django. I just use javascript's Fetch API and ajax calls worked just fine.
After doing some research on using Django as a backend for mobile apps, it seems the general consensus is to use DRF to help build APIs for the mobile app. But I had some questions:
1. How advantageous is it to use DRF when using Django as a backend for iOS apps? Can't the iOS app just make a direct ajax call to a URL on the django server to get/post data?
2. Will using DRF cut down on development time? I'm not familiar with DRF so I will need to learn it first
/r/django
https://redd.it/101of7n
reddit
Should you always use DRF when using Django as a backend for...
I'm familiar building web apps with Django. I'm currently building a iOS app in Xcode (my first time building a mobile app) and since I know...