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
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
Open-Source Hawkeye for Volleyball

​

example\_usage.gif

Hello Python Community!

I would like to present you my thesis project, where I trained models to detect and track the ball, players, the court and an additional model for action recognition. My mission is to contribute to the open-source community, create volleyball datasets and bring volleyball into the AI spotlight.

Check out the code and datasets on GitHub - VolleVision

The success of my project is counted by number of people that will benefit from it, so please consider giving it a STAR if you find it interesting or useful.

/r/Python
https://redd.it/13f815u
Introducing Solara: A Pure Python, React-style Framework for Scaling Your Web Apps

We're excited to introduce Solara: A pure Python web framework built for large, complex apps.
While there are many Python web frameworks out there, most are designed for small data apps or use paradigms unproven for larger scale. Code organization, reusability, and state tend to suffer as apps grow in complexity, resulting in either spaghetti code or offloading to a React application.
Solara addresses this gap. Using a React-like API, we don't need to worry about scalability. React has already proven its ability to support the world's largest web apps.
Solara uses a pure Python implementation of React (Reacton), creating ipywidget-based applications. These apps work both inside the Jupyter Notebook and as standalone web apps with frameworks like FastAPI. This paradigm enables component-based code and incredibly simple state management.
By building on top of ipywidgets, we automatically leverage an existing ecosystem of widgets and run on many platforms, including JupyterLab, Jupyter Notebook, Voilà, Google Colab, DataBricks, JetBrains Datalore, and more.
We look forward to your thoughts and feedback!


Check out our web (running on solara itself) at solara.dev or visit our repo at https://github.com/widgetti/solara


The application shown below allows you

/r/Python
https://redd.it/13fegbp
Which method for running Flask inside Google Colab is better?

I have a GC notebook that I want to share with non tech-savvy end users, so I looked up how to run Flask and expose to the internet in order to access it, and found this thread with two different methods?

I've tried out both of them, but I don't like idea of including my own authorization token inside a public notebook in order to use ngrok, and I'm worried about stuff like security when simply launching a server on a port. Can someone shine a light on the topic?

/r/flask
https://redd.it/13fnnk3
Python init Vs new Method - With Examples

​

https://preview.redd.it/syny6wm3ceza1.png?width=1600&format=png&auto=webp&v=enabled&s=53af28ad8bf13b806b7901fb1d0d14be9758b08f

You must have seen the implementation of the __init__ method in any Python class, and if you have worked with Python classes, you must have implemented the __init__ method many times. However, you are unlikely to have implemented or seen a __new__ method within any class.

The __init__ method is an initializer method that is used to initialize the attributes of an object after it is created, whereas the __new__ method is used to create the object.

When we define both the __new__ and the __init__ methods inside a class, Python first calls the __new__ method to create the object and then calls the __init__ method to initialize the object's attributes.

Most programming languages require only a constructor, a special method to create and initialize objects, but Python has both a constructor and an initializer.

In this article, we'll see:

Definition of the `__init__` and `__new__` methods
__init__ method and __new__ method implementation
When they should be used
The distinction between the two methods

Here's the guide👉 Python \_\_init\_\_ Vs \_\_new\_\_ Method - With Examples

/r/Python
https://redd.it/13fk77q
DataClass through decorator vs base class

This is not a protest but a question about the principles and philosophy behind the decision to use decorators in Python. Although personally I don't like decorators, I do not object to their inclusion in Python.

I am happily open to hearing arguments FOR decorators, however it seems to me that, for example, the DataClass could have been implemented as a base class and that the use of decorator is more about adding a cool new feature.

My concern is that in the pursuit of cool, Python will go down the same death spiral as the monstrosity that Java has become.

So what are the good words for decorators in Python?

/r/Python
https://redd.it/13fncv7
Logging in a flask app

So I am running a flask app that has a lot of logging. Currently the log level is set to warning. But in the event of some issue, I'd would like to see the lower level debug logs.

Is restarting the app with the log level set to debug, the only way to do this? I'd need the error to happen again in this case. How is this done on production apps? Or do they set the log level to debug right from the start?

/r/flask
https://redd.it/13fwr6t
HELP ME

/r/IPython
https://redd.it/13fvacu
When using a filefield with WTForms, is the file fully uploaded to the server to validate file format?

I noticed it took more time when I submitted a larger file with invalid file format, for the page to reload with errors. Does the server receive the full file? If it does not receive the file, then how does the server know the file type?

TL;DR: Does a large file with invalid file type submitted in a WTForms filefield put load on the server?

/r/flask
https://redd.it/13frdsz
Foreign key option

I am making an app for a BJJ tournament. I have a form to catch competitors' registration like name, weight, and rank. After that, the admin will create however many groups for competition as needed. Each competitor can only be in 1 group.

Models.py

class Group1(models.Model):
grouplabel = models.CharField(maxlength=20, unique=True)
point = models.IntegerField(default=0)


class Competitors(models.Model):
flname = models.CharField(maxlength=255)
Weight = models.IntegerField(validators=[MinValueValidator(50), MaxValueValidator(300)])
rank = models.CharField(max
length=255)
Group1 = models.ForeignKey(Group1, blank=True, null=True, ondelete=models.CASCADE, tofield='grouplabel')


[
Admin.py](https://Admin.py)

&
#x200B;

class MemberAdmin(admin.ModelAdmin):
list
display = ("flname", "Weight", "rank", "Group1")
admin.site.unregister(Competitors)
admin.site.register(Competitors, MemberAdmin)

def str(self):
return f"{self.flname} {self.Weight}"


class MemberAdmin(admin.ModelAdmin):
listdisplay = ("grouplabel","point")
admin.site.unregister(Group1)
admin.site.register(Group1, MemberAdmin)


​

Here, we can

/r/djangolearning
[https://redd.it/13fun0n