TG Telegram Group Link
Channel: Python Daily
Back to Bottom
Should I make a React/Django boilerplate?

I’m thinking of making the code I use to get SaaS projects up and running available as a paid boilerplate. This is the stack I use:

- Frontend: React, Tailwind CSS, Netlify
- Backend: Django, Postgres (RDS), Stripe
- DevOps: CircleCI, EC2
- Storage/Caching: S3, CloudFront

The frontend and backend will be on separate subdomains i.e., api.yourdomain.com and app.yourdomain.com and also be in separate repos.

The boilerplate will come with all basic SaaS functionality i.e., user accounts, teams, subscriptions etc. so you’ll only have to code the business logic specific to your app. Would anyone be interested in something like this?

/r/django
https://redd.it/1c5cm0r
Using Pandas 2 and different datetime erros

Hey Folks,

I am working on a project that uses a bit old pandas version (1.5.3). I am trying to update it and use a more recent version (2.2.2). Its the first time I use pandas 2 btw. I simply ran all my unit tests and got multiple and different errors all concerning some datetime aspects. I tried troubleshooting by searching the errors and look in pandas release note but I find really complicated. It feels like the documentation is really exhaustive but I could really use a note on principal errors one can get switching to pandas 2.

Does anyone have any handy blogpost, article, documentation that specifies this ? My focus is mainly on datetime errors when differences computed or comparaisons

​

Thanks

/r/Python
https://redd.it/1c5b5ky
i want to save the changes but it creates a new record in django

I am having this problem i don't know why

when i try to save the data it creates a new record instead of updating it

here is my view function for adding and editing

def add_contact(request, contact_id=None):
# If contact_id is provided, it means we are editing an existing contact
if contact_id:
contact = InfoModel.objects.get(rollnumber=contact_id)
else:
contact = None
if request.method == 'POST':
# Extract form data
number = request.POST.get('number')
name = request.POST.get('name')
email = request.POST.get('email')
phone = request.POST.get('phone')

# Handle dynamic fields
dynamic_fields = request.POST.getlist('new_field[]')
dynamic_data = {f'field_{i}': value for i, value in enumerate(dynamic_fields, start=0)}
if contact:
contact = InfoModel.objects.get(rollnumber=contact_id)
# If editing an existing contact, update the contact object
contact.rollnumber = number
`contact.name` = name
`contact.email` = email
`contact.phone` = phone
for key, value in dynamic_data.items():
setattr(contact, key, value)
contact.save()
else:
# If adding a new contact, create a new Contact object
contact = InfoModel.objects.create(rollnumber=number, name=name, email=email, phone=phone, extra_data=dynamic_data)

return redirect('/')  # Redirect to the contact list page after adding/editing a contact
else:
return render(request, 'contact_form.html', {'contact': contact})

/r/djangolearning
https://redd.it/1c5f2p6
Post: Crafting A Bash Script with Tmux

Hi there,

I've written a blog post sharing my tmux script for my Django development environment.

Feel free to check it out!

Crafting a bash script with TMUX

​

/r/djangolearning
https://redd.it/1c55e7a
Big O Cheat Sheet: the time complexities of operations Python's data structures

I made a cheat sheet of all common operations on Python's many data structures. This include both the built-in data structures and all common standard library data structures.

The time complexities of different data structures in Python

If you're unfamiliar with time complexity and Big O notation, be sure to read the first section and the last two sections. I also recommend Ned Batchelder's talk/article that explains this topic more deeply.

/r/Python
https://redd.it/1c5l9px
bridge — automatic infrastructure for Django

https://github.com/Never-Over/bridge

# The Problem
We built bridge to solve the most frustrating part of any new project — infrastructure. Whenever you spin up a new Django project, you usually have to manually configure Postgres, background workers, a task queue, and more. The problem is amplified when you go to deploy your application — hosting providers don’t understand anything about what you’ve configured already, so you have to run through an even more complicated process to set up the same infrastructure in a deployed environment.

# What My Project Does
bridge is a pip-installable package that spins up all of the infrastructure you need, and automatically connects it to your Django project. By adding a single line to your Django project's settings.py file, bridge configures everything for you — this means you don’t need to mess with DATABASES, BROKER_URL, or other environment variables to connect to these services.

bridge also gives you the access you need to manage these services, including a database and Redis shell, as well as a Flower instance for monitoring background tasks.

When you’re ready to deploy, bridge can handle that as well. By running bridge init render, bridge will write all of the configuration necessary to deploy your application on Render, including

/r/Python
https://redd.it/1c5lw83
UXsim 1.1.1 released: Significantly increased performance for the network traffic flow simulator

[Version 1.1.1](https://github.com/toruseo/UXsim/releases/tag/v1.1.1) of UXsim is released, which improves performance significantly.

**Main Changes in 1.1.1**

* Add setting to adjust vehicle logging time interval via World.vehicle\_logging\_timestep\_interval
* By lowering the interval (e.g., World.vehicle\_logging\_timestep\_interval=2), the simulation time can be reduced (\~20% speed up), and we can obtain vehicle trajectory data with slightly less accuracy.
* The logging setting does not affect the internal simulation accuracy. Only the outputted trajectories are affected.
* By setting World.vehicle\_logging\_timestep\_interval=-1, the record\_log is turned off, and the simulation time can be significantly reduced (\~40% speed up).
* This addresses Issue #58
* Correct route choice behavior
* Vehicle.links\_prefer and Vehicle.links\_avoid work correctly now.

**UXsim**

UXsim is a free, open-source macroscopic and mesoscopic network traffic flow simulator written in Python. It simulates the movements of car travelers and traffic congestion in road networks. It is suitable for simulating large-scale (e.g., city-scale) traffic phenomena. UXsim is especially useful for scientific and educational purposes because of its simple, lightweight, and customizable features, but users are free to use UXsim for any purpose.

/r/Python
https://redd.it/1c5q36n
bridge — automatic infrastructure for Django

https://github.com/Never-Over/bridge

# The Problem

We built bridge to solve the most frustrating part of any new project — infrastructure. Whenever you spin up a new Django project, you usually have to manually configure Postgres, background workers, a task queue, and more. The problem is amplified when you go to deploy your application — hosting providers don’t understand anything about what you’ve configured already, so you have to run through an even more complicated process to set up the same infrastructure in a deployed environment.

# The Fix

bridge is a pip-installable package that spins up all of the infrastructure you need, and automatically connects it to your Django project. By adding a single line to your Django project's settings.py file, bridge configures everything for you — this means you don’t need to mess with DATABASES, BROKER_URL, or other environment variables to connect to these services.

bridge also gives you the access you need to manage these services, including a database and Redis shell, as well as a Flower instance for monitoring background tasks.

When you’re ready to deploy, bridge can handle that as well. By running bridge init render, bridge will write all of the configuration necessary to deploy your application on Render, including a button

/r/django
https://redd.it/1c5lc9j
How to make one instance of Flask app play a sound through another instance of the same app?

The idea is to have a simple Flask app that has a client page and a server page. I would have the client page open on my phone and the server page open on my computer. I click a button on my phone and a sound is played from my computer.

I know how to play a sound using Javascript, but I'm not sure how to play a sound with Javascript through the Flask app. Any ideas?

/r/flask
https://redd.it/1c5s83e
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/1c5vh3q
I made a step by step tutorial to show how to set up JWT Authentication and then consume it in a React app

Hello! 👋

A few months ago started making videos documenting my process as I code. I find that doing this helps me develop my skills and it really brings me so much joy to share my guides as every now and then they help someone and when that happens, I feel very very happy! 😀



Anyhow, my latest [video](https://youtu.be/1pIrRTxGnJ4?si=52Nn3h4AjtXYDEn3) is about one hour and twenty-six minutes long. We start the whole process from scratch, beginning with backend development and later moving on to frontend development. In the backend, we create a RESTful API using Django and Django Rest Framework, implementing features such as user registration, login, logout, and user information retrieval with JWT authentication. On the frontend, we build a simple React application with Vite as the build tool, and use Axios for making HTTP requests to the backend API.

**Dependencies:**

**Backend:**

* Django
* Django Rest Framework
* djangorestframework-simplejwt
* django-cors-headers

**Frontend:**

* React.js
* Vite (build tool)
* Axios

Link: [https://youtu.be/1pIrRTxGnJ4?si=52Nn3h4AjtXYDEn3](https://youtu.be/1pIrRTxGnJ4?si=52Nn3h4AjtXYDEn3)


If you watch the video, I would love to hear your thoughts!
Happy coding! 😊

/r/django
https://redd.it/1c5iczb
How to override behaviour of AddIndexConcurrently in Django?

The AddIndexConcurrently django class does the following SQL:

CREATE INDEX CONCURRENTLY <idx_name>


However, I have an application that requires something a bit more complex.
I.e., I need to do some checks on the table, and if those checks pass I need to run

CREATE INDEX CONCURRENTLY IF NOT EXISTS <idx_name>


Is there a way to do that so that I can just override AddIndexConcurrently with my own class and do what I need to do there?

/r/django
https://redd.it/1c5xvbf
Using external authentication provider

I’m new to Django and authentication, and am trying to determine the correct process for authentication (using Entra ID in my case). When a user tries to access a page, that will call a view, which will then attempt to get an access token. Does the app need to redirect to a Microsoft page, or can this all be achieved in a Django template? Also, once this access token is received where is it stored?

/r/django
https://redd.it/1c5x3qo
D Can GNNs be used as model for all types of data?

Since it seems like almost every dataset can be converted to a graph :

1. Tabular - Nodes as rows with no edges between them
2. Text and Audio - Nodes as words with directed edges between adjacent words
3. Time Series - Same as 2
4. Image - Nodes as pixels with undirected edges between adjacent pixels (including diagonal)

Even if GNNs can work on all types of data, I think it may be time and space intensive to covert them into graphs, especially in case of Images.

At the same time, GNNs can make some Tabular data based ML models even more accurate - for e.g. if we have a Tabular dataset on Apartment Pricing, we can add edges between apartments in the same neighborhood so that all their prices are dependent on one another, and this models real-life phenomenon of how apartments in the same neighborhood have codependent pricing based on state of the neighborhood (for e.g. if crimes increase in the neighborhood, all apartments have their prices go down)

/r/MachineLearning
https://redd.it/1c5olyc
Easily Manage Browser Cookies Across Chrome and Firefox with Python!

Hey, r/Python community!

I've developed a versatile Python script that extracts and converts cookies from **Google Chrome and Mozilla Firefox** into commonly used formats. This tool is useful for developers and sysadmins who need to manage cookies for automation tasks, testing, or migrations between different environments.

## **What My Project Does**

### **Functionalities of the Script**

1. **Extract Cookies** from the SQLite databases of Chrome and Firefox.
2. **Convert Cookies** to either Netscape or JavaScript formats.
3. **Combine Cookies** from both browsers into a single file when working with the Netscape format. This feature is particularly useful for tools like `curl`, `wget`, or `aria2` that may require a unified cookie file.

## **Target Audience**

This script is specifically designed for:
- **Developers** testing web applications with real user cookies.
- **Sysadmins** who manage user sessions across different systems.
- **Tech Enthusiasts** looking to automate or manipulate browser data.

## **Comparison**

### **Key Features:**

- **Support for Multiple Browsers**: Extract cookies from Chrome and Firefox.
- **Flexible Output Formats**: Convert cookies to Netscape or JavaScript formats, depending on your needs.
- **Combination Capability**: Allows cookies from multiple browsers to be combined into one file, simplifying the management of multiple browser environments.

## **Usage:**

Here’s how you can use this script effectively:

```bash
python3 cookie-converter.py -b <browser> -i <input_path> -o <output_path> -f

/r/Python
https://redd.it/1c63d5g
How to detrend oscillating data?



I'm currently doing my thesis and it requires data from accelerometers to be inputted onto the Artemis modal software for analysis. I have successfully obtained the acceleration data, but unfortunately some of the data collected shows a trend (either increasing or decreasing) when the data should be oscillating at around 0 (which is the case of any structure's vibrations). Is there a software that is capable of detrending these signals? Thanks

/r/Python
https://redd.it/1c6341a
Gunicorn and Nginx

i need to deploy a flask app and after a large search i reach that i need to deploy the app through nginx and gunicorn but the problem is i am not a programmer i am start learning programming and i found it so hard and every time i search for solution i found a huge amount of solution which is looks like different for me so the question is how i deploy the app using nginx and gunicorn ?

/r/django
https://redd.it/1c640rw
Through Model Migrations

So I made a through model for an m2m field, made a migration then it freaked out on migrate.

My understanding is that it tries to delete some pre-existing relationship table to accommodate the new custom one, for some reason.. It seems like the “easy fix” youtubers default to is deleting the database but that seems like a load of bs to me especially with valuable relationship data already there.

How am I supposed to remedy this change in production? Am i supposed to rollback migrations and do something fancy in the migration file to accommodate this? What is the process I should adhere to so I can accommodate these changes upon update in production? What is the order of operations here? Bc from time to time, yeah id like to change relationships like foreign key to m2m or add my own through model here and there..

/r/django
https://redd.it/1c66398
Question: Tool for editing figures in Python

So I'm trying to switch from MATLAB to Python for my numerical simulations.

One of the things I like about MATLAB is the ability to edit figures by adding stuff (eg arrows, lines, text ... ) to the figure within the software itself. This is what I mean. It's a very handy tool in my line of work and I use it often.

I was wondering if there's any similar tool for Python. I use matplotlib and seaborn. Any suggestions would be great. Thanks guys!

/r/Python
https://redd.it/1c5ixdz
HTML Embed Code:
2024/05/01 19:48:22
Back to Top