Python Daily – Telegram
Python Daily
2.56K subscribers
1.49K photos
53 videos
2 files
39K links
Daily Python News
Question, Tips and Tricks, Best Practices on Python Programming Language
Find more reddit channels over at @r_channels
Download Telegram
DRF + React Cookie issue

I'm trying to authenticate with DRF so the user has to be logged in to hit the API endpoints I've set up, however I'm having logistical issues with it not accurately saving the cookie I guess?

CORS_ALLOWED_ORIGINS = [
    'http://localhost:3000',  # If your WordPress is running on port 3000
    'http://127.0.0.1:3000',  # For local development
    'http://127.0.0.1:8000',  # For local development]
CORS_ALLOW_CREDENTIALS = True

CSRF_TRUSTED_ORIGINS = ['https://*.fly.dev','http://localhost:3000','localhost','localhost:3000']  # <-- Updated!
CSRF_COOKIE_NAME = 'csrftoken'
CSRF_COOKIE_PATH = '/'
CSRF_COOKIE_SECURE = False   # Set True for HTTPS
CSRF_COOKIE_HTTPONLY = False  # Allows JavaScript access (needed if fetching manually)
CSRF_COOKIE_SAMESITE = 'None'  # Adjust for your cross-origin setup
CSRF_COOKIE_DOMAIN = None  # Matches the current domain (e.g., 127.0.0.1 or localhost)
SESSION_COOKIE_SECURE = False  # Set True for HTTPS
SESSION_ENGINE = 'django.contrib.sessions.backends.db'
SESSION_COOKIE_HTTPONLY = True
SESSION_COOKIE_SAMESITE = 'Lax'  # Adjust as needed for cross-origin setups

Those are my settings in settings.py.


Here is my serializer:

class UserLogin(APIView):
    permission_classes = (permissions.AllowAny,)
    authentication_classes = (SessionAuthentication,)

    def post(self, request):
        data = request.data
        # Validate data using a serializer
        serializer = UserLoginSerializer(data=data)
        if serializer.is_valid(raise_exception=True):
            email = serializer.validated_data.get('email')
            password = serializer.validated_data.get('password')
            
            # Authenticate the user
            user = authenticate(request, email=email, password=password)
            if user is not None:
                login(request, user)
                return Response(
                    {
                        "message": "Login successful", 
                        "user": {
                            "username": user.username,


/r/django
https://redd.it/1h7kvbb
Friday Daily Thread: r/Python Meta and Free-Talk Fridays

# Weekly Thread: Meta Discussions and Free Talk Friday 🎙️

Welcome to Free Talk Friday on /r/Python! This is the place to discuss the r/Python community (meta discussions), Python news, projects, or anything else Python-related!

## How it Works:

1. Open Mic: Share your thoughts, questions, or anything you'd like related to Python or the community.
2. Community Pulse: Discuss what you feel is working well or what could be improved in the /r/python community.
3. News & Updates: Keep up-to-date with the latest in Python and share any news you find interesting.

## Guidelines:

All topics should be related to Python or the /r/python community.
Be respectful and follow Reddit's Code of Conduct.

## Example Topics:

1. New Python Release: What do you think about the new features in Python 3.11?
2. Community Events: Any Python meetups or webinars coming up?
3. Learning Resources: Found a great Python tutorial? Share it here!
4. Job Market: How has Python impacted your career?
5. Hot Takes: Got a controversial Python opinion? Let's hear it!
6. Community Ideas: Something you'd like to see us do? tell us.

Let's keep the conversation going. Happy discussing! 🌟

/r/Python
https://redd.it/1h7nue4
How Can Flask Help in Data-Related Roles?

Hi everyone,

I'm starting an internship in about three months as an Analytics Engineer. My mentor mentioned I'll be using Flask during the internship. I want to train and be fully prepared before I begin.

I have a few questions:

1. How does Flask help in data-related roles like mine?
2. What kind of resources should I explore to get better at Flask?
3. What types of projects should I try to build with Flask to improve my skills?
4. Do you have any ideas on where I can find project datasets or examples? I’ve checked Kaggle, but it doesn’t seem to have anything Flask-specific.

Thanks in advance for your suggestions and advice!

/r/flask
https://redd.it/1h5p7b9
How we made Celery tasks bulletproof

Hey folks,

I just published a deep dive into how we handle task resilience at GitGuardian, where our Celery tasks scan GitHub PRs for secrets. Wanted to share some key learnings that might help others dealing with similar challenges.


**Key takeaways:**

1. Don’t just blindly retry tasks. Each type of failure (transient, resource limits, race conditions, code bugs ) needs its own handling strategy.
2. Crucial patterns we implemented:
- Ensure tasks are idempotent (may not be straightforward,
- Used `autoretry_for` with specific exceptions + backoff
- Implemented `acks_late` for process interruption protection
- Created separate queues for resource-heavy tasks

**Watch out for:**

1. Never set task_retry_on_worker_lost=True (can cause infinite retries)
2. With Redis, ensure tasks complete within visibility_timeout
3. Different behavior between prefork vs thread/gevent models for OOM handling

---

For those interested in the technical details: https://blog.gitguardian.com/celery-tasks-retries-errors/


What resilience patterns have you found effective in your Celery deployments? Any war stories about tasks going wrong in production?

/r/Python
https://redd.it/1h7xr6s
pytest-fixture-forms - A new plugin to simplify testing parameter variations

Hey Python testing enthusiasts! I'm excited to share a pytest plugin I've been working on that makes testing different parameter variations much cleaner and more maintainable.

# What my project does

If you've ever found yourself writing lots of parametrized tests for different API inputs, credentials, or configuration combinations, you know it can get messy quickly. This plugin lets you organize these variations as fixture methods in a class, making your tests more structured and easier to maintain.

Here's a quick example:

class UserCredentials(FixtureForms):
@pytest.fixture
def valid_user(self):
return {"username": "john_doe", "password": "secure123"}

@pytest.fixture
def invalid_password(self):
return {"username": "john_doe", "password": "wrong"}

def test_login(user_credentials):
response = login_service.authenticate(**user_credentials.value)
if user_credentials.form == "valid_user":
assert response.status_code == 200


/r/Python
https://redd.it/1h7ztqd
VCAT: Video Transcriber and Translator





# Have you ever wanted to share videos to your non bilingual friends? 🌎


Fear not because I (Claude) have made a noscript that does exactly that!


## What My Project Does


Type in a video URL along with the target language and the program will:

A) Download the media from the URL (Uses youtube-dlp so most websites are compatible)
B) Transcribe it (srt file output)
C) Translate it (srt file output)
D) Add subnoscripts using ffmpeg

All fully automated of course!

🔍 https://github.com/tikene/video-caption-and-translate - You can see some sample translations on my repo to get an idea of how the output video looks


## Target Audience 👥


If you have any friends who, for example, aren't fluent with English, you may have ran into some frustration when trying to share movies, videos or shows that you like. That's what motivated me to make this noscript, making it so you can easily share your interests and build human connections regardless of the language barrier (It's all about making the world a better place 💁‍♀️)



## Comparison 🔄

The projects I could find relating to this subject either:
- Don't accept URLs
- Don't work with long videos
- Don't add the subnoscripts directly to the video
-

/r/Python
https://redd.it/1h85e6v
ML Trading Bot that uses Ranked Ensemble Learning

I created a ML Trading Bot - trained it for a little over 3 years with 24 years of data and started it live on November 20, 2024. It's been going over a little more than 2 weeks, but it's been doing great so far - not indicative of how it will perform but it's had a great debut if you can say that.

GitHub Repo: https://github.com/yeonholee50/AmpyFin

Bot Website: https://ampyfin-website.onrender.com/

What My Project Does

In essence, the trading bot ranks the strategies and gives them weights based on their overall performance while giving slight bias to recent performance (this is so it is reactive to current market trends and adjusts accordingly). These weights determine how much influence they have on the trading strategy. That's the oversimplified explanation of how the bot works. A more denoscriptive explanation is done on the website as well as README

Target Audience

Reason why I'm posting here is because I'm currently looking for contributors who have some expertise in Python (maybe want to contribute or just interested) on the trading strategies side. The more trading and diverse strategies there are, the better the bot will perform. This project is aimed towards developers interested in contributing or just anyone interested in the

/r/Python
https://redd.it/1h7qtzs
Does Flask Support Async? When Should It Be Used?

I've been learning Flask and came across the concept of async in web frameworks. Does Flask support async functions?

If it does what are some practical scenarios where async would be useful in a Flask application? Are there any specific limitations or things to keep in mind when using it?

Would appreciate any guidance or examples to understand this better

/r/flask
https://redd.it/1h81041
PyCon US 2025 Registration Opens

Howdy Pythonistas :)

PyCon US 2025 registration and Travel Grant applications are officially open!

Early bird tickets are available until the first 500 tickets are sold or until January 6, 2025 (whichever comes first). Register today to get your discounted tickets and help us spread the word!

P.S. You can also Submit a Talk for the next 2 weeks!

- Blog Announcement
- Travel Grants

/r/Python
https://redd.it/1h89mmg
Saturday Daily Thread: Resource Request and Sharing! Daily Thread

# Weekly Thread: Resource Request and Sharing 📚

Stumbled upon a useful Python resource? Or are you looking for a guide on a specific topic? Welcome to the Resource Request and Sharing thread!

## How it Works:

1. Request: Can't find a resource on a particular topic? Ask here!
2. Share: Found something useful? Share it with the community.
3. Review: Give or get opinions on Python resources you've used.

## Guidelines:

Please include the type of resource (e.g., book, video, article) and the topic.
Always be respectful when reviewing someone else's shared resource.

## Example Shares:

1. Book: "Fluent Python" \- Great for understanding Pythonic idioms.
2. Video: Python Data Structures \- Excellent overview of Python's built-in data structures.
3. Article: Understanding Python Decorators \- A deep dive into decorators.

## Example Requests:

1. Looking for: Video tutorials on web scraping with Python.
2. Need: Book recommendations for Python machine learning.

Share the knowledge, enrich the community. Happy learning! 🌟

/r/Python
https://redd.it/1h8fj53
Question about route decorators

Do I have to specify the methods in both route decorators or is it okay to do it in just one of the two of my choice?

@app.route('/', methods='GET', 'POST')
@app.route('/index', methods='GET', 'POST')
@loginrequired
def index():
    return render
template('index.html', noscript='Home')

/r/flask
https://redd.it/1h5snak
Accenture interview experience 2024 | I got selected | I used to python to ace the coding round

I am a computer science student and I have multiple offeres. I have recently attended accenture interview and got selected. I have made a video on my interview experience : https://youtu.be/bq3FrksBpwc?si=3tv\_QZNOhy4yhRLy . I will share my amazon interview experience and other experiences (like Tredence) in the follow videos.

/r/Python
https://redd.it/1h8jkfc
So I'm Working on Making Django a Feasible Option for Modern Fullstack Development

The noscript says it all. I want to use django for modern full-stack development. No awkward integrations between React and Django or {% insert_frontend_framework_here %} integrations. So I've opted to build my expertise in django + htmx + alpinejs.

Professionally, I've worked as a systems administrator and IT support person. Just 4 years. I've never really been a dedicated, qualified, or frankly educated developer (whichever's worse), but recently, I've wanted to really focus on building a career as a developer, and I just don't want to use any frontend frameworks that are opinionated. Might be a fool's task, but I don't think I can convince myself to work hard on it any other way. I want to do Python and Django, and I want to do it professionally. I don't know if I should die on that hill, but I really want to.

Rant aside, I'm actually working towards it. I've made a cookiecutter template for building Django apps. https://github.com/lusayo-nyondo/cookiecutter\_djangoapp if anyone wants to see. I want to use it to develop SaaS apps and my goal is to either get a good job or have one of my projects give me a job. In the absence of a job, my plan

/r/django
https://redd.it/1h8dwjz
I have launched my App to generate Podcasts with AI that I have built with Flask

Honestly, developing this whole project has been quite an odyssey. I started with a bit of a crazy idea after seeing what NoteBookLM was but I felt that it was a bit short with its capabilities, like not being able to use custom voices that only work in English or not being able to accept article or Web URLs to make Podcasts, so I decided to start my project called PodcastAI Studio and it has been quite a journey since I started playing with the LLMs I was going to use or the TTS with the ability to clone voices and deliver a good result, it was quite a journey and I also thought about other people wanting to create or build on this whole system so I decided to create some APIs for developers, also a library that works as an API client and now I'm here making this Reddit post telling all this XD, I hope you like the whole experience and I leave you the links to my App and the API documentation along with some images

https://preview.redd.it/9ksmk6opvc5e1.png?width=1366&format=png&auto=webp&s=854414a7af509d9e034d44c54ea43c1633ef6cea

https://preview.redd.it/2aukj6opvc5e1.png?width=1366&format=png&auto=webp&s=09ce2a36964275c846a4c35b8b396d0f57856a12


App: https://www.podcastai.tech/

API Docs: https://www.podcastai.tech/api/docs

/r/flask
https://redd.it/1h8ksz7
Creating a multiplayer quiz game. Cant figure out how to create a lobby.

I'm trying to make backend for an online multiplayer quiz game. front end will be done according to the finished backend by someone else. premise is simple, users log in. they initiate the game, the game will show them both questions and a timer (calculated at front end), at the end someone will win and game will end. Game logic is simple, user creation and log in process is also simple. but I am having hard time on starting on how the matchmaking/lobby and match start process will work. any insights?

/r/djangolearning
https://redd.it/1h81rf2
Location of npm in my windows 11

I have been installing django-tailwind and when I was done. I somehow could run the

python `manage.py` tailwind install command because of the error below

CommandError:

It looks like node.js and/or npm is not installed or cannot be found.



Visit `https://nodejs.org` to download and install node.js for your system.



If you have npm installed and still getting this error message, set NPM_BIN_PATH variable in `settings.py` to match path of NPM executable in your system.



Example:

NPM_BIN_PATH = "/usr/local/bin/npm"


I am not sure how to solve this because I cannot find an npm.exe file anywhere

/r/djangolearning
https://redd.it/1h8p54m
Flet vs Streamlit PWA and conceptual questions

I'm new to flet, but I'm experienced Flutter developer plus I'm a Generative AI Engineer and worked with streamlit or Gradio. I have some conceptual questions.
Q1. If flet uses Flutter, then why does the flet Flutter plugin require a URL? Why cannot the flet UI "live" all together in Flutter?
Q2. Since there's a URL needed anyway, what's the advantage of using it vs for example having a Streamlit UI displayed in a PWA?
Q3. Let's say I develop a personal assistant in flet. Can the assistant access my location, heart rate, my camera (for multi-modal Gen AI), microphone and speakers (for voice assistant functionalities)?

/r/Python
https://redd.it/1h8nzyy
Async django, who is using it and why?

I am curious to know the use cases for async django, and whether there was a performance improvement in doing it.

/r/django
https://redd.it/1h8rd7v
Anyone Using Temporal?

I recently learned about temporal.io through a tech talk. Does anyone in the Django community use this as an alternative to something like Celery? It sounds too good to be true.

/r/django
https://redd.it/1h8tcp9
Django-Q2 in Azure Web App

I'm trying to migrate an overgrown POC app from an ex-colleague's desktop to the cloud. It's urgent, so I had to just figure out a plan of action quickly and run with it.

The app is a Django application with management dashboard, along with a whole range of tasks that need to be run at specific times throughout the day.

My colleague used to just run the server on his machine and have some Cron jobs configured for the tasks.

I've turned the Cron jobs into Django-Q2 schedules, which seem to run fine locally.

I've made 2 Azure Web Apps, one that starts up the Django application and hosts the dashboard with the "runserver" command in the startup noscript,which runs fine.

The other should be responsible for running the jobs, so it sets up the schedules in the startup noscript and then runs the "qcluster" command.

This last app keeps restarting, with message "Site startup probe failed after X seconds" and the jobs are not being executed (correctly). I assume this is because this app does not host a web server that can be probed by Azure, but I'm not sure.

2 questions:
* How can I quickly work fix / work around this issue so the app

/r/djangolearning
https://redd.it/1h7z3dc