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
"Should" i normalize everything ? Data modeling question

Hey guys,

I have a model called Problem that contains many fields : difficulty, status, category.

Each of these fields have 3 entries. For example, difficulty field has these values : "Easy", "Normal", "Hard".

Should i create a whole model with its own table just for the difficulty field and make it a foreign key of the Problem model ? As below :


from django.db import models

class Difficulty(models.Model):
name = models.CharField(max_length=50)

def __str__(self):
return self.name

class Problem(models.Model):
name = models.CharField(max_length=50)
difficulty = models.ForeignKey(Difficulty, on_delete=models.CASCADE)

def __str__(self):
return self.name

Or should i just create a multiple choice field and keep the logic in my code :

from django.db import models


/r/djangolearning
https://redd.it/13dixxh
Bevy v2.0

I've created a dependency injection framework that works similarly to Fast API using type annotations. You only need to use the inject decorator and the dependency function to indicate what should be injected.

Installation

pip install bevy

Simple Example

from bevy import dependency, inject

class Demo:
def init(self):
self.message = "Hello World"

@inject
def example(thing: Demo = dependency()):
print(thing.message)

example()

That'll handle creating an instance of Demo and injecting it into the example function.

Useful Links

Blog post explaining in more detail

Documentation

GitHub

/r/Python
https://redd.it/13dvdk8
Your Django-Docker Starter Kit: Streamlined Development & Production Ready

Hey there,

I've crafted a Django-Docker starter kit titled "**Django-Docker Quickstart**" to kickstart your Django projects in no time.

This kit includes Django, PostgreSQL, Redis, Celery, Nginx, and Traefik, all pre-configured for your ease. Nginx and Traefik are set up for your production environment to handle static files, proxy requests, route requests, and provide SSL termination.

You'll also find tools such as Pytest, Pytest plugins, Coverage, Ruff, and Black, making your development and testing process smoother.

Check it out here: **Django-Docker Quickstart**

Enjoy coding and please star the repo if you find it helpful!

P.S: Feedback and suggestions are always welcome! 🚀

/r/django
https://redd.it/13e1t5v
Took a web development job without much experience, am I doomed?

Okay so please don't ask how or why, but for the next year or so 50% of my 40 hour work week will be dedicated to developing a web application for a public authority.

The goal is to develop an application that offers users to fill out an extensive evaluation about sustainability.
Afterwards, they should receive information and visualizations/diagrams building on their answers. They should also receive a score for their sustainability in different categories and suggestions to improve on.
Both the answers and the suggestions should be stored in a connected database.

That’s about it.
I have a little bit of programming experience.
I know the basic principles like classes, objects, control structures like if/for/etc.

I don’t really have experience in web development though apart from fooling around a bit in Django. Honestly that’s why I want to choose Django as a framework for it.

Do y’all think it is possible if I spent around 20hrs/week on this project?

Obviously the first step would be to learn Django and web development in general the next couple weeks.

I would appreciate any input and also tips for any resources to start off.

/r/django
https://redd.it/13e1b5o
Thursday Daily Thread: Python Careers, Courses, and Furthering Education!

Discussion of using Python in a professional environment, getting jobs in Python as well as ask questions about courses to further your python education!

This thread is not for recruitment, please see r/PythonJobs or the thread in the sidebar for that.

/r/Python
https://redd.it/13e7jfp
Running Multiple Gunicorn Instances for Low-Traffic Websites

I've been exploring the use of Gunicorn and Nginx to serve Django websites, and it's generally recommended for its performance benefits. However, I have a question regarding running multiple websites on the same server with Gunicorn.


If I want to run multiple websites, it seems that I need to run separate instances of Gunicorn for each site. My concern is whether this approach will unnecessarily consume CPU and RAM resources, especially if the websites have low traffic.


In the past, I've used a LAMP stack to run multiple websites without requiring dedicated processes for each site. This makes me wonder if the modern approach with Gunicorn and Nginx is better in terms of resource usage and efficiency.


Could anyone shed some light on this? Am I missing something in understanding the benefits of running multiple Gunicorn instances for multiple websites, even if they have low traffic?


I appreciate any insights or experiences you can share.


Thanks in advance!

/r/django
https://redd.it/13eed6n
word2num: Convert complex "word numbers" to numerical values

Hey all, I just published my first Python package called word2num. It converts written numbers like "one hundred and twenty-five" or "nine and three quarters" to their numerical values. There are a handful of other packages out there that do this already, but they're mostly no longer maintained and do not support fractional values (the key feature I need for my project).

It supports a variety of types of numbers and uses configurable fuzzy string matching to account for typos. It only supports English at the moment, but contributions for other languages would be more than welcome.

If you want to give it a try, you can pip install word2num.

from word2num import word2num
word2num("twenty nine and a half") # 29.5

Check out the GitHub repo for more usage info and examples. My experience in Python is quite limited, so if anything comes across as non-Pythonic, I'd appreciate a heads-up! 🙌

/r/Python
https://redd.it/13e8tzc
The Ultimate Django Guide for Beginners and Beyond

Hello, fellow Redditors! I remember the days when I first started learning Django. It was both exciting and challenging, and at times, I wished I had a comprehensive guide to help me navigate this new territory. That's why I decided to write this in-depth article on Django – to make the journey easier for you.

This guide explores everything from Django's history and core features to its project structure, comparison with other Python frameworks, and the future scope of Django development. It's a resource I wish I had when I started, and I hope it can be beneficial for those who are just beginning or looking to deepen their Django knowledge. Dive in, explore, and let's enter the fascinating world of Django together!
https://danielbuilescu.com/blogs/learn-python/understanding-django-an-introduction-to-pythons-web-framework

/r/django
https://redd.it/13ei9m2
Any good course on Python microservices?

Trying to make the simplest one possible. Looking for a real quick and basic example with a message broker.

/r/Python
https://redd.it/13eqxic
D Simple Questions Thread

Please post your questions here instead of creating a new thread. Encourage others who create new posts for questions to post here instead!

Thread will stay alive until next one so keep posting after the date in the title.

Thanks to everyone for answering questions in the previous thread!

/r/MachineLearning
https://redd.it/13as0ej
N Anthropic - Introducing 100K Token Context Windows, Around 75,000 Words

Anthropic has announced a major update to its AI model, Claude, expanding its context window from 9K to 100K tokens, roughly equivalent to 75,000 words. This significant increase allows the model to analyze and comprehend hundreds of pages of content, enabling prolonged conversations and complex data analysis.
The 100K context windows are now available in Anthropic's API.

https://www.anthropic.com/index/100k-context-windows

/r/MachineLearning
https://redd.it/13etub0
django project review

I build this site https://ottomantravels.com using django. now I am thinking was it worth when I could easily use WordPress. I know WordPress can be troublesome to handle.

one more suggestion should I leave the admin url with the site ? does it cause any security vulnerability.

/r/django
https://redd.it/13epprd
I nearly finished deploying, some advice on finishing touches?

So I set up DRF on Railway, it looks like this:

https://preview.redd.it/0tevffr9f8za1.png?width=1215&format=png&auto=webp&v=enabled&s=b592d19d558b0a30a0dd3a7a433e259e1d5cbd1a

Trying to use Celery, this is how django\_contettype table looks like:

https://preview.redd.it/ch06slr9f8za1.png?width=1135&format=png&auto=webp&v=enabled&s=c969f4b5e3f23af159ffbd8ff228e716b12fe699

2nd page:

https://preview.redd.it/y2jdphr9f8za1.png?width=1196&format=png&auto=webp&v=enabled&s=6bdb7dca1114f31e92fec56db0a820a4721981ac

**So because I'm seeing this, I think I'm getting somewhere (It is my first time deploying). I want celery (not beat) to work in production, but I'm not sure what to do now. This is to show what I've done, do you have any advice of how I can make celery work in production please?**

This is my **tasks.py,** I also have celery.py file configured properly in the same folder as settings.py is, and hosted on Railway with Redis.

from celery import shared_task
from time import sleep

import smtplib
import ssl
from email.message import EmailMessage
from django.conf import settings

@shared_task
def send_the_email():
sleep(some_variable)

email_sender = settings.EMAIL_HOST_USER
email_password = settings.EMAIL_HOST_PASSWORD

em =

/r/django
https://redd.it/13etak6
Tips on fine-tuning Transformer models for multilingual customer support?



Hi everyone,

We're looking for some experiences and techniques for fine-tuning Transformer models to handle multilingual customer support requests and provide accurate responses. We have a customer support chatbot that is powered by a multilingual Transformer model. We're some difficulty getting the model to provide accurate responses in different languages, so we'd like to hear what others are doing to fine-tune their models for this purpose.

I've been looking at a few different options, such as the use of language-specific embeddings and incorporating specific domain knowledge into the model. What techniques have you used to fine-tune your Transformer models for multilingual customer support applications?

And do you guys know any platforms aside from the one from OpenAI? We're looking at Finetuner+ because it promises to enhance LLMs and LMs capabilities within a secure and controlled environment, but I would still love to hear your thoughts about it and other possible alternatives.

Thank you in advance for your help and input!

/r/Python
https://redd.it/13eshf0
For some reason the code below won't enter the stripe webhook.

I based the code on this [https://blog.miguelgrinberg.com/post/accept-credit-card-payments-in-flask-with-stripe-checkout](https://blog.miguelgrinberg.com/post/accept-credit-card-payments-in-flask-with-stripe-checkout) .

​

​

routes.py

from flask import Blueprint , render_template, redirect, url_for, request, abort, flash

from app.payment.forms import EmptyForm, EmailForm


import stripe

# might need to adjust templates
payment = Blueprint('payment', __name__, template_folder='templates')

from flask_login import current_user

# import db from flaskblog folder in __init__.py.
from app import db

from app.models import User, Payments

from redmail import outlook

import os








@payment.route('/donations', methods = ['POST', 'GET'])
def donations():


/r/flask
https://redd.it/13f62zq
Appending data to a CSV file within a flask app

Hi! As seen in the title, I can't seem to add/append data or text to the csv that I have uploaded to my flask app that is being deployed in Google Cloud Run. But when I try it locally using Jupyter Notebook, it seems to work just fine. 

Here is the code:

#load the csv
features = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
url_data = pd.read_csv("RetrainDatabase.csv",low_memory=False)

#append the new data features
url_data.loc[len(url_data )] = features

#save the new csv
url_data.to_csv("RetrainDatabase_V2.csv", index=False)

/r/flask
https://redd.it/13fcehr
The Ultimate Django Guide for Beginners and Beyond

Hello, fellow Redditors! I remember the days when I first started learning Django. It was both exciting and challenging, and at times, I wished I had a comprehensive guide to help me navigate this new territory. That's why I decided to write this in-depth article on Django – to make the journey easier for you.

This guide explores everything from Django's history and core features to its project structure, comparison with other Python frameworks, and the future scope of Django development. It's a resource I wish I had when I started, and I hope it can be beneficial for those who are just beginning or looking to deepen their Django knowledge. Dive in, explore, and let's enter the fascinating world of Django together!
https://danielbuilescu.com/blogs/learn-python/understanding-django-an-introduction-to-pythons-web-framework

/r/djangolearning
https://redd.it/13eiac8