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
I made a Django+react SaaS boilerplate that leverages the Django Admin to give end-users access to data (via Stripe subscriptions)

Hi!

From the Github repo:

​

>YaSaas is an open-source SaaS boilerplate built on Django REST Framework and React, offering a flexible foundation for entrepreneurs looking to monetize their data.With seamless integration of Stripe subscriptions and leveraging Django admin functionalities.

Will you join me in the darkside where Django Admin can be used by end-users?

/r/django
https://redd.it/18e538s
Built a Python script to get Spotify stats!

Hey r/Python,

I wrote a Python script while I was playing with the Spotify API which can get your Spotify Stats :)

https://preview.redd.it/b32baddnc55c1.png?width=640&format=png&auto=webp&s=e1720187f521f72cf4a6e356a678e6c613018623

Repository Link : https://github.com/ni5arga/spotify-stats-python

Feel free to star and fork!

/r/Python
https://redd.it/18dyf8o
Connecting Django API to a Django crud app. How?

Watched a tutorial in how to create an API with Django and created several APIs with this tool. Now the next step I am planning is to create a basic crud app using Django where I will have JavaScript within a JS template file perform very basic math which will take the user numeric value input from an input tag within a form. My question is since i never developed a full stack application. I am completely lost. I want for the backend (Django) to get the data from the user and store it onto a database SQLite3. As a beginner who has basic knowledge of the client side using HTML5, CSS3 and JavaScript and very little knowledge with Django but only creating APIs. Can anyone give me a recommendation on what is the easiest way to create a crud app which calls an API? Should I allow Django to perform the math or is it ok to allow the client which is JavaScript to perform the math and have Django get and send to the database? Complete newbie! Thank you all.

/r/django
https://redd.it/18e556p
Recently visited page middleware

Supercharge User Experience with Recently Visited Pages Middleware!

Easily implement a recently visited pages feature in your Django rest framework app using the ‘recently-visited-page-middleware’ package. Track and retrieve user-specific page history effortlessly. Enhance user engagement and navigation. Get started with a simple pip install:

pip install recently-visited-page-middleware

Github repository link : https://github.com/Abiorh001/recently_visited_page_middleware

/r/django
https://redd.it/18e8sg2
Trending on GitHub globally 3 days in a row: SuperDuperDB, a Python framework for integrating AI with major databases (making them super-duper)

It is for building AI (into your) apps easily without complex pipelines and make your database intelligent (including vector search), definitely check it out: https://github.com/SuperDuperDB/superduperdb

/r/Python
https://redd.it/18ec2p7
Working on updating the PyDev debugger to use sys.monitoring... I just love my multi-monitor setup with LiClipse ;)

Ok, so, I'm updating the PyDev debugger to use sys.monitoring...Hopefully it'll land soon (I've been working on and off in it for a while and not that much is missing for a final release).

Now, I stopped to breath a little and I just realized I really like using LiClipse with multiple monitors.

My window arrangement using LiClipse

/r/Python
https://redd.it/18eb2aq
Django email, need help

I'm trying to send an email to people when 3 or fewer days are remain, I'm using Django, this is the models.py in my main app, I want to automatically send emails when 3 days or less remain I'm using 4.2

class sub(models.Model):

id = models.UUIDField(default=uuid.uuid4, primary_key = True, editable = False)

provider = models.CharField(max_length=70)

tier = models.CharField(max_length=40)

date_started = models.DateField(auto_now=False, auto_now_add=False)

date_end = models.DateField(auto_now=False, auto_now_add=False, )

author = models.ForeignKey(User, on_delete=models.CASCADE)



def remain(self):

today = date.today()

remaining_days = (self.date_end - today).days

return(remaining_days)

​

​

​

def get_absolute_url(self):

return reverse('sub-detail', kwargs={'pk':self.id})

/r/django
https://redd.it/18eh2h9
What 12,500 Surveys and 6,300 Salaries Data Points Taught Us About Jobs in Germany & Switzerland?

Over the past 2 months, we've delved deep into the preferences of jobseekers and salaries in Germany (DE) and Switzerland (CH).

The results of over 6'300 salary data points and 12'500 survey answers are collected in the Transparent IT Job Market Reports. If you are interested in the findings, you can find direct links below (no paywalls, no gatekeeping, just raw PDFs):

https://static.swissdevjobs.ch/market-reports/IT-Market-Report-2023-SwissDevJobs.pdf

https://static.germantechjobs.de/market-reports/IT-Market-Report-2023-GermanTechJobs.pdf

/r/django
https://redd.it/18eldlp
Unable to connect to the local mysql database

I am trying to create a basic authentication framework for which I need to connect my flask app to a local mysql database, and my credentials seem to be correct as the pymsyql code below works and the localhost page renders the database contents correctly, however, the flasj_mysqldb code does not work and gives the error "error": "'NoneType' object has no attribute 'cursor'"
I have tried looking at different sources all of which say the database credentials might be a problem, but I know for sure that this is not the case. Any help is appreciated.

erroneous code:

from flask import Flask, jsonify
from flaskmysqldb import MySQL

server = Flask(name)
server.config["MYSQL
USER"] = "superuser"
server.config"MYSQL_PASSWORD" = "superpass"
server.config"MYSQL_HOST" = "localhost"
server.config"MYSQL_DB" = "auth"
mysql = MySQL(server)

@server.route("/")
def index():
try:
with mysql.connection.cursor() as cur:


/r/flask
https://redd.it/18ep76i
Django Messages Vs HttpResponse message for Forms

I understand that messages are used to display after a page refresh but let's say you're using HTMX so there isn't a page refresh, would it still be ok to use messages rather than a HttpResponse to show a message or is there some sort of disadvantage of doing so?

I find messages to be a little cleaner than a simple HttpResonse for this case.

Example:

messages.add_message(self.request, messages.SUCCESS, "Thank you! We will get back to you as soon as possible.")

vs

return HttpResponse('<p class="success">Thank you! We will get back to you as soon as possible.</p>')  

&#x200B;

/r/django
https://redd.it/18eq1ny
Django without using Models

I am pretty new to Django with 2-3 years of Python experience writing automation scripts for various tasks. I have read the documentation twice, but I am not sure if what I applied here is the best practice .

The use case is the following:

1. I want the user to be able to login-logout to my site
2. I have create a basic web navigation using html
3. I have created a django form that the user can supply 5 parameters and submit
4. I am creating an item in a directory of my current app (e.g ./myapp/my_directory)

Everything works fine while in development but I am just not sure if that is the best practice here. The worklfloaw on step 4 is that

1. I am creating a directory of let's say a car firm and then
2. subdirectories of their car models,
3. I save some pictures (.jpg) of each model
4. I zip the car firm's directory and delete the original directory
5. I provide a list of downloadable links for all the .zip files in that directory and my plan is to wipe the directory once per month so I doesn't occupy a

/r/django
https://redd.it/18en11d
No changes detected with MAKEMIGRATION command after moving to new DataBase

Hello! I am Trying to Learn Database Setup and migrations in different Scenarios.

So this is what I did
1. Connected to the POSTGRES database on railway.app.
2. Ran first migration command for Django (after initiating project)
3. Removed the Entire DataBase on Railway (to see how Django responds)
4. Created a New Database again on the railway.app
5. Updated the variables for new DB credentials in Django
6. After Running the DEVELOPMENT server, I Found the Session Table Missing Error
7. Tried MAKE MIGRATIONS command, result (No changes detected)


So how Do you Deal with this Scenario, considering I have backed up the Data and I no need to worry about losing Data. How do I restore or reperform Migrations as this is not for app but the migrations which Django needs to Run the entire Project.


&#x200B;

/r/django
https://redd.it/18evv2x
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/18eqnxv
I'm running Django through docker and I want to make it live-update when a change is made to the project (templates included). Is it possible?

A possible way I found was through volumes and docker-compose, but it didn't work for me and I didn't fully understand how it worked.

I also found something along the lines of watchdog, but I don't think it works for a docker context

Any help is appreciated!

/r/django
https://redd.it/18ehiz3
I made Arrest, a small utility to wrap your API calls from your Python application

Hey guys! I'm super excited to announce arrest. It is a small library that you can use to define the structure of the REST Apis your Python application will be interacting with. it provides a straightforward way to call the different routes in your API and additionally enriches them with Pydantic classes for data validation. And it is also backward compatible with pydantic@v1.10.13.

I would greatly appreciate your feedback and useful opinions/improvements on this. Here are the docs if you wanna check that out.

Thanks a lot!

/r/Python
https://redd.it/18eys56
Kanban in the CLI with kanban-python

HoHoHo again
After some great feedback and feature requests I present to you the new version of
kanban-python your kanban terminal app written in python:

Code here: https://github.com/Zaloog/kanban-python


Install with:
python -m pip install kanban-python


during the course of the last month the following features were added:
- moved to XDG Basedir Spec for config and data files
- Directory Scanner to automatically scan e.g. .py files for '# TODO' Patterns and generate tasks out of that.
- better options to change settings and show task details
- a new report function to generate an overall report (.md file) and
show a github-like contribution table

Thanks for your support so far, and I hope kanban-python helps you boost your productivity.
If you have feedback, feel free to reach out here, or create an issue.

Have a great day

/r/Python
https://redd.it/18es539
Livestream PS5 or PC Gameplay into OpenCV

I wrote this script after surprisingly finding very little existing code online about capturing windows.

This script can be used to capture PlayStation 5 gameplay in real time into OpenCV for further image processing, or capture a game window on PC.

Along the way I found out that graphics is more complicated than I thought. Windows does not make it particularly easy to capture windows that are hardware accelerated, and most existing libraries do not work when the window goes off screen or is obscured. My script works with both with good performance!

This could be used to analyse the video for some event (using image/text detection), send a message, record some score, or even act as a master for a microcontroller robot (Arduino etc) operating the controller!

https://github.com/lorcan2440/View-PS5-Screen-Remote-Play

The repo contains a guide for how to set it up. If you'd like to use it and are having trouble just leave a comment here or raise an issue there and I'll try to help. I've also made a C++ implementation since most of the relevant functions are just calling from Windows DLLs so the conversion was easy. C++ will have slightly better performance but you need to set up OpenCV for C++ by yourself

/r/Python
https://redd.it/18f5vyy
I like this docstring from django source code

If found this:

"""
This module collects helper functions and classes that "span" multiple levels
of MVC. In other words, these functions/classes introduce controlled coupling
for convenience's sake.
"""

So nice.

Especially this line:

In other words, these functions/classes introduce controlled coupling
for convenience's sake

controlled coupling

I like it.

/r/django
https://redd.it/18f6khm
SCRABBLE IN TERMINAL

Hey everyone, this is my first serious python project. I (hope) it works in terminal after cloning it and running rework file. All other info is in README so make sure you check how to play it before you do. Hope you all like it!

I'm planning to advance it and add some graphics. Any piece of advice would be appreciated!

Scrabble repository on github

In case you find any error or anything to improve you can fork it and make pull requests.

&#x200B;

Scrabble

/r/Python
https://redd.it/18f9tb6