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 do you manage your Django project versioning?

I am using poetry with package-mode disabled to manage the virtual environment for my Django project. How can I implement semantic versioning releases with poetry and GitHub Action for my Django project?

/r/django
https://redd.it/1b4o37r
Where to learn Django like Flask Mega-Tutorial from Miguel Grinberg?

I learned how to use Flask by following Miguel Grinberg's Flask Mega tutorial, which was great. I learned how to build and deploy a Flask microservice web app and what it looks like to write clean and effective code for the app which makes me (a beginner) feel like he writing an industry-standard code layout. Is there any tutorial or book similar to this in Django?

/r/flask
https://redd.it/1b4s3fs
How to manage vercel deployment?

Currently I am using vercel to deploy a django app for a project I maintain but one of the difficulties I've encountered is that it doesn't look like there's a way access the shell (so I can't run manage.py commands to do things like create a superuser). One of the ideas I had was to automatically create a supper user through secrets on deploy, but I haven't fully investigated it yet.

I am mainly using vercel so I can use its free tier to very the software / provide instructions to the person on the team who will be paying for the real deployment once we officially release. If there's a better alternative for this (I am using Vercel + Vercel Postgres + Vercel Blob right now) please let me know.

One of the dumber ideas I thought of was temporarily adding an endpoint to inject in the user creation and then close it up after I was done.

Also one of the things I'd like to do is run custom management commands (basically for DB management/pruning/exporting). Are there any integrations for Django Admin that allow for this?

/r/django
https://redd.it/1b4q8x7
An extremely modern and configurable Python project template

# What My Project Does

Rob's Awesome Python Template is a cookiecutter template meant to bootstrap python projects using modern best practices.

At the very basic level it includes:

- Modern pyproject.toml without any legacy files (no setup.py or setup.cfg).
- Development Management using Makefiles.
- Configuration Management with Pydantic.
- PyPI Publishing from Git Tags using setuptools-scm.
- Formatting and Linting with Ruff.
- Typing with mypy.
- Lockfiles (requirements.txt, requirements-dev.txt) with uv.
- Testing with pytest.
- CI/CD using Github Actions.
- Precommit Hooks using the precommit framework.

It also has a ton of optional features:

- Github Actions for CI
- Cross Platform (arm, arm64, amd64) Docker containers using the Multi-Py project.
- Optionally use any combination of FastAPI, Click/Typer, Celery, and Sqlalchemy.

I've used this template for a number of projects- QuasiQueue, Paracelsus, and Fedimapper being some nice examples. If you want to see exactly what the project would generate today you can review the examples repository which builds a few projects using different options to give people a feel for what things can look like.

# Target Audience

Any developer looking to bootstrap their projects can use this! What makes it really helpful is that you get a modern, high quality project with tools already configured before you even write a single line of

/r/Python
https://redd.it/1b4qwds
Created a Django react template and deployed it

/r/djangolearning
https://redd.it/1b4ufbv
Class properties and methods?

Hi,

I am working in a django repo where the views and the forms and the all the things inherit and inherit some more.

How do you guys manage to get an understanding of what the actual resulting methods and properties of any given class is? Do you lean into the ide capabilities (which? how??) or do you guys have a protocol?

​

thx S

/r/django
https://redd.it/1b4y1kg
Sunday Daily Thread: What's everyone working on this week?

# Weekly Thread: What's Everyone Working On This Week? πŸ› οΈ

Hello /r/Python! It's time to share what you've been working on! Whether it's a work-in-progress, a completed masterpiece, or just a rough idea, let us know what you're up to!

## How it Works:

1. Show & Tell: Share your current projects, completed works, or future ideas.
2. Discuss: Get feedback, find collaborators, or just chat about your project.
3. Inspire: Your project might inspire someone else, just as you might get inspired here.

## Guidelines:

Feel free to include as many details as you'd like. Code snippets, screenshots, and links are all welcome.
Whether it's your job, your hobby, or your passion project, all Python-related work is welcome here.

## Example Shares:

1. Machine Learning Model: Working on a ML model to predict stock prices. Just cracked a 90% accuracy rate!
2. Web Scraping: Built a script to scrape and analyze news articles. It's helped me understand media bias better.
3. Automation: Automated my home lighting with Python and Raspberry Pi. My life has never been easier!

Let's build and grow together! Share your journey and learn from others. Happy coding! 🌟

/r/Python
https://redd.it/1b52uds
Text-to-speech with python

Greetings pythonistas,

I'm thrilled to share with you my latest article which delves into the amazing python package, pyttsx3. Explore the capabilities and how interesting the Text-to-Speech(TTS) package is

Read the full blog post here:
https://jeffmint.hashnode.dev/code-that-speaks-a-beginners-guide-to-pyttsx3-text-to-speech-tts-in-python

If you find the content intriguing and would like to actively contribute to its development, I'm excited to announce that it's an open-source initiative! Feel free to explore the repository, and let's join forces to enhance and elevate the usage of the package together. Your collaboration and ideas are invaluable in making it even more remarkable.
https://github.com/Minty-cyber/CodeThatSpeaks

Cheers to building something great together! πŸš€

/r/Python
https://redd.it/1b51w2t
When exactly should you use .js when using a flask db

Hi all, I'm trying to figure something out. Since I started writing my website, anything that involved modifying my database I would do an onclick call to a .js routine. But as I've gotten further and seen other peoples code I'm seeing that is not necessary as it can simply be done through routing and forms. I was doing it simply because the original tutorial I followed used .js. Is there some reason I'm not seeing? And generally speaking when is it a good idea to start mixing .js in?

/r/flask
https://redd.it/1b56ksn
Flask Admin does not hash the User password

The code encrypts from the registration page but does not encrypt from Flask Admin. I have read examples online and written this code. I think the values for target, oldvalue and initiator are incorrect. I did not understand what they should be initialised with.


class User(db.Model, UserMixin):
__tablename__ = "user"
user_id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(20), unique=True, nullable=False)
firstname = db.Column(db.String(20), nullable=False)
lastname = db.Column(db.String(20), nullable=False)
email = db.Column(db.String(80), unique=True, nullable=False)
password = db.Column(db.String(80), nullable=False)
agreed_terms = db.Column(db.String(80), nullable=False)
reg_datetime = db.Column(db.DateTime, default=dt.now)
role = db.Column(db.String(20), nullable=False)

def __str__(self):
return self.username

@event.listens_for(User.password, 'set', retval=True)
def hash_user_password(target, password, oldvalue,

/r/flask
https://redd.it/1b57g1f
Append tags when creating a post with a many to many relationship in Flask

I want to add multiple tags to a new post at creation. The post and tag models are in a many to many relationship. I'm expecting the loop to create a tag then append it to the post. Is the 'NoneType' error coming from the routes code or the models code? Is there a different beginner friendly approach?

models.py

tags = sa.Table(
'tags',
db.metadata,
sa.Column('postid', sa.Integer, sa.ForeignKey('post.id'), primarykey=True),
sa.Column('tagid', sa.Integer, sa.ForeignKey('tag.id'), primarykey=True)
)
class Post(db.Model):
tablename = 'post'
id: so.Mappedint = so.mappedcolumn(primarykey=True)
body: so.Mappedstr = so.mappedcolumn(sa.Text)
timestamp: so.Mapped[datetime] = so.mapped
column(index=True, default=lambda: datetime.now(timezone.utc))
userid: so.Mapped[int] = so.mappedcolumn(sa.ForeignKey(User.id), index=True)
author: so.MappedUser = so.relationship(backpopulates='posts')
language: so.Mapped[Optional[str]] = so.mapped
column(sa.String(5), default='')


/r/flask
https://redd.it/1b51415
<!DOCTYPE html> over {% load x %}

The internet forgot to include this title.

Doctype has to be the very first line of an html document or "template", the {% load x %} templatetag occupies one line, they belong under the <!DOCTYPE html> line.

New users need to be able to find this in the internet. and this info is not anywhere else.


Great software! I finished learning it today as a hobbie! I finally know how to make websites.

Thank you.


/r/django
https://redd.it/1b5c4er
Django DebugToolbar not working in docker compose

Only came across this article that's addressing my probelm - https://blog.juanwolf.fr/posts/programming/2017-08-26-django-debug-toolbar-not-showing-docker-compose/

&#x200B;

But how do i continue to develop using docker compose and get debugToolbar to work? I wonder if any of you have dealt with this annoyance before. It works great when i run locally.

&#x200B;

So far, the compromise i found is...run django locally and then run the rest of the services (db, redis etc) via the compose file but would ideally like to develop within docker-compose since i have everything mounted and can see code changes instantly...just debugtoolbar not liking docker network setup... thanks

/r/django
https://redd.it/1b52zmd
Can't Resolve Unintended "Id" and "Business" Fields in Django Formset



Hey Django Community,

I'm in a bind with a Django formset that's rendering extra labels "Id:" and "Business:" which aren't supposed to be there. I've already tried excluding these fields explicitly in my CreditCardFormSet
but to no avail. Here's a brief rundown of the situation:


CreditCardFormSet = inlineformset_factory(

BusinessDetail, CreditCard,

fields=('card_type', 'last_8_digits'),

extra=3, max_num=3,

can_delete=False,

exclude=('business', 'id',) # Tried excluding here

)

{% for form in formset %}

<div class="form-control w-full">

{% for field in form %}

<label>{{ field.label }}:</label>

{{ field }}

{% endfor %}

</div>

{% endfor %}


To debug, I printed out the fields of the first form in the formset, and to the dict output included both 'id' and 'business' keys, which I hadn't defined in my formset fields:


print(formset.forms[0\].fields) # Output: dict_keys(['card_type', 'last_8_digits', 'id', 'business'\])




my CreditCardFormset doesn't define 'id' or 'business' as fields, yet they're showing up.

/r/django
https://redd.it/1b5dypr
I hate typing out every 'self.x = x' line in an init method. Is this alternative acceptable?

class Movable:
def init(self, x, y, dx, dy, worldwidth, worldheight):
"""automatically sets the given arguments. Can be reused with any class that has an order of named args."""

nonmembers = #populate with names that should not become members and will be used later. In many simple classes, this can be left empty.

for key, value in list(locals().items())1:: #exclude 'self', which is the first entry.
if not key in nonmembers:
setattr(self, key, value)

#handle all nonmembers and assign other members:

return

I always hate how redundant and bothersome it is to type "self.member = member" 10+ times, and this code does work the way I want it to. It's

/r/Python
https://redd.it/1b5bc8g
shavis - Visualize SHA256 and SHA1

https://github.com/kernel137/shavis
Install with

pip install shavis
shavis is (secure hash algorithm visualization), is a CLI tool that can hash any file (Only through SHA256) and create an 8x8 pixel image displaying the hash through themed colours.


What My Project Does:

Main functionality of this CLI tool is taking the 64 digit hex number (SHA256 hash) and, through 16 hex colors in ascending order, turning it into a 8x8 pixel image that can then be scaled to powers of two.
Shavis also supports piping: echo -n "Hello World!" | shavis

This also works for git hashes, since git hashes are SHA1, images for this hash are 8x5, I think with some clever integration, its possible to integrate a small res picture of a git commit hash to quickly visualize the hash within vscode or some other platform.
A quick way to get a visual of the last git commit while within a local git repository is:

git rev-parse HEAD | shavis -g

What do you guys think? Is it a worthwhile investment to implement other hashes? Is it an interesting project? Do you guys have any ideas about what to add to it?


/r/Python
https://redd.it/1b5em7s
Automatic wallpaper changer - Wallpapertime

Hello everyone, I decided to write a small program on python that allows you to change the wallpaper by setting them a time interval.

Github: https://github.com/Niamorro/Wallpapertime

# What My Project Does:

WallpaperTime is a versatile Python application designed to dynamically change your wallpaper based on specified time intervals.

# Target Audience:

for those who need the functionality of this program

##Comparison:
WallpaperTime stands out with its focus on time-based intervals for wallpaper changes. Here's how it differs from existing alternatives:

# Time-Driven Wallpaper Changes:

WallpaperTime distinguishes itself by allowing users to set specific time intervals for wallpaper changes

# System Tray Integration:

The application seamlessly integrates with the system tray.

# Autostart and Minimize Options:

WallpaperTime offers autostart and minimize options, ensuring a smooth and unobtrusive startup experience.

# Intuitive User Interface:

In summary, WallpaperTime brings a customization and user-friendly features, making it a standout choice for those who want to curate their desktop experience b
ased on time.

/r/Python
https://redd.it/1b5gsoh
MongoDb Aggregation Tutorial for complex Mongodb Queries

πŸš€ Calling all developers! πŸš€
I have created this amazing Tutorial on MongoDb Aggregation ( link ) for writing complex queries. Do have a look on it and all feedbacks are appreciated. Like, share, and subscribe for more coding excellence! πŸŒπŸ’» #MongoDB #Aggregation #WittyCoder #CodeMasters #Programming #TechTalks #LearnToCode #HappyCoding πŸ”₯

/r/Python
https://redd.it/1b5o4sa