Python Daily
2.57K subscribers
1.48K photos
53 videos
2 files
38.9K links
Daily Python News
Question, Tips and Tricks, Best Practices on Python Programming Language
Find more reddit channels over at @r_channels
Download Telegram
Best way to serve React App with Flask

Hey all,

I'm pretty experienced with Flask however React is something I've been picking up recently. Basically I have a React App and a basic Flask app. I'm looking at ways to "tie" authentication between the Flask/React app and wondering what is popular with a Flask/React set up.

My options appear to be (after looking at Miguels blog here):

1. Nginx that serves the React App and Flask app. Issue a JWT from Flask (after user logs in) and implement a component in React to check the JWT, if it does not exist/expired then redirect the user back to Flask app.
2. Nginx that serves the Flask app and place the React App "behind" Flask (e.g. through a Flask route). I don't love this option but it does seem cleaner.

Is there another option I'm missing or maybe a easier/better way to handle this? Anything I'm overlooking?

​

Thanks!

/r/flask
https://redd.it/sc3sxg
Tuesday Daily Thread: Advanced questions

Have some burning questions on advanced Python topics? Use this thread to ask more advanced questions related to Python.

If your question is a beginner question we hold a beginner Daily Thread tomorrow (Wednesday) where you can ask any question! We may remove questions here and ask you to resubmit tomorrow.

This thread may be fairly low volume in replies, if you don't receive a response we recommend looking at r/LearnPython or joining the Python Discord server at https://discord.gg/python where you stand a better chance of receiving a response.

/r/Python
https://redd.it/sc06b9
Can I use Django to administer Office 365?

I have an idea popped up in my mind and now I need to understand if this is even possible and feasible. To begin with, this will be a Django app that can access Office 365 to pull following data:

1. the licenses currently assigned to user
2. the mailing lists a user is member of
3. when the user changed his password
4. the user account expiration date
5. to reset MFA for a user
6. and etc.

This app will be used by local helpdesk colleagues. They don't have access to Azure AD and Office 365 admin portal.

Now the question is, is it possible (well I guess yes) and more importantly, which libraries, tools I need to make it real.

PS. This is going to be my pet project, and while doing it, I am hoping to improve my Django skills. Therefore, any advice, guidance and hints are appreciated.

/r/django
https://redd.it/scc71d
Setting up Django with uWSGI and nginx - I've been trying to figure this out for 5 days now. Please help...

I'm trying to set up nginx server with my django app and uWSGI, by following this tutorial: https://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html
I've been able to follow it up until the socket testing. The test itself doesn't produce an error, but localhost:8000 always returns 502 bad gateway error. I have been troubleshooting this for hours but can't figure out what I'm doing wrong.

/etc/nginx/nginx.conf:
```
#user http;
worker_processes 1;

#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

#pid logs/nginx.pid;

events {
worker_connections 1024;
}

http {
include mime.types;
default_type application/octet-stream;
# load configs
include /etc/nginx/sites-enabled/*;
types_hash_max_size 4096;
server_names_hash_bucket_size 128;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;

location / {
root /home/<userprofile>/Projects/<project-name>/mymoon/journey/templates/journey/; # /usr/share/nginx/html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
}
```
/etc/nginx/sites-available/mymoon.conf
```
# mymoon_nginx.conf

# the upstream component nginx needs to connect to
upstream django {
server unix:///home/Projects/<project-name>/mymoon/journey/journey.sock; # for a file socket
server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}

# configuration of the server
server {
# the port your site will be served on
listen

/r/djangolearning
https://redd.it/sc7jt2
Django: React vs templating

Hi I am a beginner. I was wondering: what kind of thing are you not able to do with templates and need to resort to a front end framework such as React? Thanks :)

/r/djangolearning
https://redd.it/sclie3
Working example of AIORTC

I am searching for a working example of aiortc(python implementation of webrtc). Now there are some "good example" in documentation itself but none of them are practical enough. for example. how to connect two or more peer through aiortc or how to make a conference room using aiortc. If any one of you know any git repo or website from where I can see a working example or any one of you made something more practical using aiortc and happy to share please share.
Thank you!

/r/flask
https://redd.it/scmly3
Wednesday Daily Thread: Beginner questions

New to Python and have questions? Use this thread to ask anything about Python, there are no bad questions!

This thread may be fairly low volume in replies, if you don't receive a response we recommend looking at r/LearnPython or joining the Python Discord server at https://discord.gg/python where you stand a better chance of receiving a response.

/r/Python
https://redd.it/scrr00
HTMX vs django unicorn for dynamic pages

I worked a lot with Django unicorn, and I kinda loved it. But once you use more Django-unicorn components, loading components slows down the website, I'm talking about 5 components with 20 db queries, even I'm indexing my models and using selectrelated and everything for db performance, still Django unicorn makes everything slow.

For people who tried HTMX and Django unicorn, which one do you think is better?

BTW, I'm using JavaScript
exclude and partial update in Django unicorn.

/r/django
https://redd.it/scm4do
Simple problem with Jinja 2

Hi ! I'm having a small issue. I want to make an if statement in jinja 2 that has an ''or'' operator.

It's supposed to show only the users that have admin set to 1 and level set to 9 (9 is a boss and 1 is an admin).

I have this :

{%for u in users%}
{%if u.admin == 1% or u.level == 9%}
<option value='{{u.id}}'>{{u.fname}} {{u.lname}}</option>
{%endif%}
{%endfor%}

But i get this error:

>jinja2.exceptions.TemplateSyntaxError: expected token 'end of statement block', got 'u'

Someone has a clue ? Jinja is not super clear on that in their documentation

/r/flask
https://redd.it/scu73u
I just hosted my little website about programming, I want to track some statistics and I immediately thought of Google Analytics but after research I found out about huge amount of hate for them and problems with GDPR and other law things. I am looking just for basic stats, should I really avoid GA?

Hi. My question is basically in the topic. I always thought that Google Analytics is a Go To thing for everyone in terms of statistics, fast, reliable, a lot of options but lately I started reading and apparently GA is even banned from several EU countries already?

I started thinking, that after all I am not running any e-commerce, so I don't need to exactly track if my user got to checkout or not but it would still be nice to have some insight of how long people are reading my stuff and browsing each pages etc.

I know how to google and I found a lot of alternatives but I have to say that I found 3 recurring problems with them.

1. They cost quite a lot, 35 euros per month for a website with 100 000 views??
2. Some of them can be self hosted but they advise: "App server minimum recommended configuration: 2 CPU, 2 GB RAM, 50GB SSD disk." for a website with 100 000 views or less? It sound absurd I think?
3. And some of them look simply, kinda sketchy ...

I am wondering, what are you guys doing on your django websites?

Are you using GA after all?

Or you are

/r/django
https://redd.it/scj3df
How to join two tables with different number of rows SQLAlchemy

Hi all. I'm having a hard time querying and joining two tables with different number of rows and columns together. I have looked into many online solutions, but none of the queries have been giving me the result I need.

I have been stuck on this problem for 3 days, and I would REALLY appreciate it if someone could look at my StackOverflow post here:

https://stackoverflow.com/questions/70857410/how-can-i-join-two-tables-with-different-number-of-rows-in-flask-sqlalchemy

Thank you so much in advance!

/r/flask
https://redd.it/scso9t
Step by step, can anyone tell me what I'm doing wrong?

Hi guys,

I feel like an idiot and I am ready to cry.

I normally do my web development on my Linux machine but I am trying to develop a small web app to help me at work. I've made some functioning websites before, so I'm kind of shocked that I can't even get a basic site running at the moment. I'm having trouble with Python importing my app modules. I tested this step by step and I keep getting the error, I'd appreciate any feedback on this.

I know it is overkill, but showing each step I take to see if we can find the problem:

1) I create a new folder to house my project, and within that folder create a virtual environment and activate it accordingly.

https://preview.redd.it/rvptj5bsryd81.png?width=960&format=png&auto=webp&s=f4918475f5127af403e28f0f65cc9a12377b9b54

https://preview.redd.it/ocxgtxptryd81.png?width=960&format=png&auto=webp&s=8bb3c8b05f02b7c331e0d1b37a2ba197c0f4445b

2) I install django and my other Python libraries (Crispy Forms, Pillow, etc.) to said virtual environment.

https://preview.redd.it/85ikqriuryd81.png?width=960&format=png&auto=webp&s=172c9a7a5a3e8378f434de7e3a9095e25d82b40e

3) I create a new django project and a new app, both within the same root directory containing the venv.

https://preview.redd.it/g00piolyryd81.png?width=960&format=png&auto=webp&s=3609eeaa09f9168a7262b8dd161bd266eda27b1a

4) Next I normally migrate the database and create my super user account.

https://preview.redd.it/3fijunl0syd81.png?width=960&format=png&auto=webp&s=f584be1623f8fda3d0071e510c1d0897a1edda96

https://preview.redd.it/rhmq5441syd81.png?width=960&format=png&auto=webp&s=55e7b5eeefb332fc26740c3a9b57d84f4e669d22

&#x200B;

5) First I check to make sure the site is running without any errors (python manage.py runserver)

https://preview.redd.it/yodwdpw3syd81.png?width=960&format=png&auto=webp&s=a0d8d502243def9bc181405f749bbec6698162b4

https://preview.redd.it/aa515l94syd81.png?width=856&format=png&auto=webp&s=94b4563be04f4f1f241e99aeb6dcf9126a687783

&#x200B;

6) Next I go to settings.py and add

/r/django
https://redd.it/scxw4m
general question about saved temporary data in RAM

I have a very general, might be stupid, question about the variables passing through cells.

I constantly have several large data in shape like (3, 100*300, 250), well, maybe not that large, but there are multiple of these variables passing between cells, and I am wondering, how long will they be kept in the Operating system's RAM ?

If, say, I have stored 5G of variables, will these data in RAM be removed when the system needs to use more memory (like heavy gaming?)

I ask this cause I am using jupyternotbook as my main data analysis tool, and I definitely want my data and analysis to be reliable and stable.

/r/JupyterNotebooks
https://redd.it/scv6j0
How to sort posts on blog by ascending and descending?

Sorry if this is basic, I'm a beginner.

On the homepage of my blog, I've got a for loop that gets every post and lists them. By default this sorts them ascending.

What would be the best way to let a user toggle between sorting the posts by ascending or descending?

/r/flask
https://redd.it/scsmnm