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
How to login to Django views from React?

Currently I am facing an issue where I can sign in from react accurately but my django session is not updated based on whether I login or logout from react.

What I am expecting is that when I sign in through react, my current user view in django will be changed to demonstrate the current user I signed in as from react but at this moment no changes can be seen. Using jwt tokens from react, I am able to access the current user view and get the correct user but this change can only be observed in react and the server side isn't adjusted to have the correct user logged in.

The following image demonstrates my problem: problem

Please provide any help that you can as I have been stuck on this problem for roughly a week now and have been unable to find a solution.

This is how I handle sign ins in react.

//Signs In the user through Django
const handleSignIn = async ()=> {
try {
const response = await axios.post('http://127.0.0.1:8000/api/login/', {


/r/djangolearning
https://redd.it/184xb6g
Difference in setting up test client inside a client fixture

Hi. I'm learning Flask and Python in general, and I'd like to know if these two ways of creating and using a test_client differs in any way? I don't like the nested "with" in the second method. First one seems more clear to me. Both of them works the same as far as I can tell... Are there any downsides of any of them or is this just a matter of preference?

1. ​

​

@pytest.fixture
def client():

app = createapp('../configs/testconfig.py')

with app.appcontext():
try:
db.create
all() # I'm setting up the db for testing purposes here
yield app.testclient()
finally:
db.drop
all()

2.

@pytest.fixture
def

/r/flask
https://redd.it/185324g
Why not Django?

Hi I am nodejs developer who get started this journey with Django. I have a task to make ai/machine learning model for production. As far as I know, 99% of people uses flask or fastapi as their choices. I want to know why and I am away from python world for a long time so I can’t even remember cli commands. I just want to know why and any resources or open source projects from you, thanks.

/r/django
https://redd.it/1853ush
ImportError: cannot import name 'requestctxstack' from 'flask'

Any idea what cause the problem?

==================================================

Traceback (most recent call last):

File "/opt/flask\
apps/runserver.py", line 2, in <module>

from invweb import app

File "/opt/flask_apps/invweb/__init__.py", line 19, in <module>

import invweb.views

File "/opt/flask_apps/invweb/views.py", line 3, in <module>

from flaskext.mysql import MySQL

File "/opt/flask_apps/.venv/lib/python3.10/site-packages/flaskext/mysql.py", line 7, in <module>

from flask import _request_ctx_stack as _ctx_stack

ImportError: cannot import name '_request_ctx_stack' from 'flask' (/opt/flask_apps/.venv/lib/python3.10/site-packages/flask/__init__.py)

===================================================

Requirement.txt content:

====================================================

bcrypt==4.0.1

blinker==1.7.0

click==8.1.7

Flask==3.0.0

Flask-MySQL==1.5.2

itsdangerous==2.1.2

Jinja2==3.1.2

MarkupSafe==2.1.3

PyMySQL==1.1.0

Werkzeug==3.0.1

===================================================

&#x200B;

The server is ubuntu 22.04.04 LTS.

&#x200B;

&#x200B;

&#x200B;

/r/flask
https://redd.it/184yhiq
Looking to hire a Django developer

Hi all,

I'm looking for a Django developer. I don't really trust Indeed or Linkedin because of the bots so I'm deciding to post the job here instead.

A bit about the company

Blendable ([blendable.ca](https://blendable.ca))
We provide insurance and group benefits to employers
Located in Canada

Relevant candidates

Intermediate developer (i.e. not a junior, not a senior)
2-3 years experience with Django
Candidates working from Canada will be given preference

Job details

95k salary
Fully remote
Work your own hours
You'll be collaborating with the rest of the development team to build out our web app.

How to apply

If you're interested, DM me with the following information:

Your name & email
Where you're located
A link to your website/portfolio/resume
Any questions about the role/job

/r/django
https://redd.it/185adey
Tuesday Daily Thread: Advanced questions

# Weekly Wednesday Thread: Advanced Questions 🐍

Dive deep into Python with our Advanced Questions thread! This space is reserved for questions about more advanced Python topics, frameworks, and best practices.

## How it Works:

1. **Ask Away**: Post your advanced Python questions here.
2. **Expert Insights**: Get answers from experienced developers.
3. **Resource Pool**: Share or discover tutorials, articles, and tips.

## Guidelines:

* This thread is for **advanced questions only**. Beginner questions are welcome in our [Daily Beginner Thread](#daily-beginner-thread-link) every Thursday.
* Questions that are not advanced may be removed and redirected to the appropriate thread.

## Recommended Resources:

* If you don't receive a response, consider exploring r/LearnPython or join the [Python Discord Server](https://discord.gg/python) for quicker assistance.

## Example Questions:

1. **How can you implement a custom memory allocator in Python?**
2. **What are the best practices for optimizing Cython code for heavy numerical computations?**
3. **How do you set up a multi-threaded architecture using Python's Global Interpreter Lock (GIL)?**
4. **Can you explain the intricacies of metaclasses and how they influence object-oriented design in Python?**
5. **How would you go about implementing a distributed task queue using Celery and RabbitMQ?**
6. **What are some advanced use-cases for Python's decorators?**
7. **How can you achieve real-time data streaming in Python with WebSockets?**
8. **What are the

/r/Python
https://redd.it/185hzaf
Google ads API not running on admin pod but is running on celery worker

So basically the title,

I am working on a project where I need to run a custom method in Django admin of some model, in this method I am acquiring a connection to the Google ads API and making a request to create something. While running this method in the admin pod, the process got stuck, but when I made a celery task it was fine and worked just as I expected, this is not the first project that this problem happened to our team, I couldn't find any explanation and I was wondering why did it happen, would love to get you insight on it.

/r/django
https://redd.it/185r1z1
miniloop: a minimal, pedagogical event loop implementation

https://github.com/roee30/miniloop

The PEPs introducing the async/await syntax don't specify exactly how event loops work, considering it an implementation detail. If you are curious about how event loops work in Python, you might have noticed that reading through asyncio's code is challenging, to say the least.

That's why I have created a minimal event loop implementation with step-by-step explanations. It shouldn't be used for anything other than learning purposes. It is 362 lines in size, but many of them are documentation. Before diving in, make sure you understand generators. You can use the server.py script to see the loop in action.

The implementation is inspired by asyncio, but I only added what was necessary in order to make a simple server work. In particular, my Task and Future are roughly analogous to asyncio's, but I didn't find a need to implement Handles (perhaps because I didn't implement the call_* methods).

I learned a lot writing this and I hope it will be useful to others as well.

/r/Python
https://redd.it/1859c26
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
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
Just like in the real world, django also has F expressions. Quick tip

/r/django
https://redd.it/185rb8e