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
D.O. litespeed droplet with django

Hello I just fired up a droplet with openlitespeed and django. So it comes preinstalled with an app and a project right? So I put in my model into models.py and receive this error when trying to migrate:
from django.core.management import execute_from_command_line

ModuleNotFoundError: No module named 'django'



The above exception was the direct cause of the following exception:



Traceback (most recent call last):

File "/usr/local/lsws/Example/html/demo/manage.py", line 22, in <module>

main()

File "/usr/local/lsws/Example/html/demo/manage.py", line 13, in main

raise ImportError(

This is prebuilt image with django i suppose. Ihave the virtualenvironment activated. Why is this error coming out ? Thanks to those who can help



/r/djangolearning
https://redd.it/1ivlyg5
How can I retain django form data after a user is redirected

I am trying to create a complicated form set up that has the user authenticate with google as part of the steps to the form.

I'm currently using django-formtools library and what I want is:

1. User fills out data in form 1
2. Based on data filled in form 1, have them authenticate with google on step 2.
3. Once authentication is done, redirect them back to the form, but on to the next step.

I'm currently using the SessionWizardView, but what is happening is that after Google auth is done, it redirects back to the form page but its back on Step 1 of the form, and not the correct 3rd step that I would want it to be on, and it doesn't seem to have record of what the user has already submitted.

Is there a better way to do this without using the django-formtools library? Seemed like a match for the workflow I want, but I need a way to get back in the form flow after the redirect is done.













/r/django
https://redd.it/1iwm4jc
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/1iwdbgs
Shareable product or platform to demonstrate coding project skills?

Does anyone have any recommendations for a platform or product (paid or free) that lets you record yourself coding on a moderately complex project?

Basically, I'm aiming for something that would obsolete doing toy exercises for every employer you interview with. Something you could slap on your resume and they just navigate to a link to view it. Ideally it includes AI completions or is compatible enough you could use an IDE with them.

By moderately complex I mean going many steps above LeetCode type problems. You would need to demonstrate that you can use tools to quickly navigate and understand a decent size codebase. It would need to be something you couldn't memorize.

/r/Python
https://redd.it/1iwwcjk
Open-Source MICT AI Ethics Toolkit: Practical Examples for Mitigating Bias and Hallucinations

Hey r/python,

I'm excited to share an open-source project I've been working on with the Boredbrains Consortium: the **MICT AI Ethics Toolkit**. It's designed to help developers build more responsible and trustworthy AI systems by providing practical tools and examples for addressing ethical concerns. The toolkit is built on the **Mobius Inspired Cyclical Transformation (MICT)** framework, which provides a structured, iterative process for integrating ethical considerations *throughout* the AI development lifecycle.

**What My Project Does:**

The MICT AI Ethics Toolkit provides reusable Python (and JavaScript) functions, classes, and example implementations for addressing common ethical challenges in AI development. It's *not* a standalone framework; it's a set of tools designed to be integrated *into* existing projects, using the MICT framework for a structured approach. Currently, the toolkit includes:

* **Bias Detection:** Functions to calculate disparate impact ratios for binary classification models, helping you identify and mitigate potential biases in your datasets and models.
* **Hallucination Detection:** Functions for detecting potential hallucinations in large language model outputs, using simple string-matching against a knowledge base. (More sophisticated methods to come!)
* **Example Implementations:** Runnable examples demonstrating how to use these tools within a MICT cycle

/r/Python
https://redd.it/1iwunjl
Should I use Flask or React

I currently have access to a server which provides API endpoints which I cannot modify. I want to create a UI for it. Should I go for using Flask to fetch the data from the API using the routes, or just go straight to React?

My biggest problem is that this server only accepts basic authentication. If I use flask, I can have a login page where I ask the user for a username and password, I then query my API endpoint to see if I have the correct combination of username and password, and then save this username and password in a database (in hashed format). If I use React, I need to ask the username and password from the user and I have to either store this locally or in cache. I am assuming that if I do this, it will be stored in plain text.

My questions are:

1. Which implementation would provide more security and convenience? Flask or React?
2. Is it even stupid of me to think of using Flask instead of React?

P.S. First time asking here, and I am at my wits end trying to figure out which of the two I should use.

/r/flask
https://redd.it/1iwtroa
I finally implemented auto-complete in my terminal based productivity managers code editor, Ticked!

**NEST+**

* Fixed various QOL issues and bugs pertaining to the general code and text editing experience
* Added support for general code completion via Jedi and a custom auto-completion popup
* **Only works in Python currently**
* Local variables, methods, etc. are stored and are automatically appended to the suggestion list.
* Python syntax instantly accessible; common decorators, standard libraries, operators, etc.

[Read the full release notes here](https://github.com/cachebag/Ticked/releases/tag/v0.3.1)

**Install with Homebrew:**

`brew tap cachebag/ticked`
`brew install ticked`

**Install via Pypi:**

`pip install ticked`

I appreciate everyone being so patient and continuing to suggest improvements. School and work has been crazy so far this year, but this project is going to be fleshed out in great detail in the coming months. I'm working on a lot of revamping of the system and continuously improving upon existing features instead of falling to scope creep.

/r/Python
https://redd.it/1iwghxb
Django Template not working as expected

Hello everyone.

I have the following objects

```
class ManyToManyObjects(models.Model):
id
ObjectA = models.ForeignKey('A')
ObjectB= models.ForeignKey('A') #Different Objects, but for sake of argument lets say they are the same.
Objectmatch = models.CharField}
ObjectScore = models.IntegerField()

Class A(models.Models):
id
data
```
(Redacted some of it for simplicity, but these are the main fields for this interaction.)

And I have the following in my Django Template:
```
{% assign prevmatch '' %}
{% assign lastA ''%}
{% assign lastB ''%}
{% for match in ManyToManyObjects %}
{% if prevcod != match.Objectmatch %}
... //just some sort of header for the table


/r/djangolearning
https://redd.it/1iu2c47
I built a new playground for Python

https://codiew.io/ide?t=py

Playground (backend) based on Docker images with Google gVisor isolation.

It supports program arguments, pretty output for JSON and I will add a lot feature soon



/r/Python
https://redd.it/1ix0rf0
How do i resolve "Working out of context"?

/r/flask
https://redd.it/1iwzzk2
Open-source reverse proxy to remove sensitive data from OpenAI API calls

Hi, r/Python!

I'd like to share the project I've been working on during the last few weekends.

- Code: https://github.com/edublancas/sanitAI
- Video tutorial: https://youtu.be/bdA7T6Z6YQ4

What My Project Does

SanitAI is a reverse proxy that intercepts calls to OpenAI's API and removes sensitive data. You can add and update rules via an AI agent that asks a few questions, and then defines and tests the rule for you.

For example, you might add a rule to remove credit card numbers and phones. Then, when your users send:

> Hello, my card number is 4111-1111-1111-1111. Call me at (123) 456-7890

The reverse proxy will remove the sensitive data and send this instead:

> Hello, my card number is <VISA-CARD>. Call me at <US-NUMBER>


Target Audience

Engineers using the OpenAI at work that want to prevent sensitive data from leaking.

Comparison

There are several libraries to remove sensitive data from text, however, you still need to do the integration with OpenAI, this project automates adding, and maitaining the rules, and provides a transparent integration with OpenAI. No need to change your existing code.

/r/Python
https://redd.it/1ix4m99
Sparx automation hacks

It’s probably unlikely but i was wondering if anyone here could create a code that would automate your sparx homework and do it for you I’m not very technical in coding and i don’t know how but it would be something like from this yt video https://youtu.be/uu3VSDdSKCg?si=SlejJH9-soJ9Jydn

/r/Python
https://redd.it/1ix77t8
Need help with flask

I am getting started with flask. Can anyone explain how it works , how projects are structured , etc.

/r/flask
https://redd.it/1iwykut
Django Devs: What do you wish your project had in place before you were hired?

I'm considering starting a start-up web project that will likely have to be built on a framework such as Django.

As I'm in the very early concept phase, I'm looking to understand what information and level of detail I should have in place before hiring my first dev, (and/ or if a Django dev is a cost effective way of helping me take it from concept to a clear plan, before execution)?

I'd also be keen to understand if I'd need any other types of resource/ roles to get going, or if a Django dev is all that I'd need. Any sort of guidance on start up documentation I should have completed or suggests from this experienced community would be greatly appreciated! Thanks!



/r/django
https://redd.it/1iwz88b
High memory usage on delete

/r/django
https://redd.it/1ixb489
Beginner learning - Function base or Class Base approach

English isn't my first language, so sorry about the grammar, and weird way organize sentence. I end up here is because after researching the community for Django I find out the English community were way more helpful.

Goal for learning Django : Planning to learn the Django fundamental and fully understand the idea of how it's work, not just using it by following other's tutorial making stuff. I want to reach the level that I can only using documents and my brain to create something I like.

Background :
\- 6 months in my self-taught journey, knowing all basic fundamental concepts and syntax of Python, HTML, CSS, Javascript. Mainly trying to focusing on the backend. For Django I had follow their tutorial, and recently I'm read the book "Django for Beginners(5th Edition)"

Problem:
\- I can see the benefit of Class-base approach more fit into DRY principle.

\- BUT ! I had a feeling that I'm not fully get the idea of class, class inheritance or the idea of OOP. I think I understand the concepts of class , but when come to using it. It's always had the unsure what I'm doing.

\- So, for beginning of the Django learning

/r/djangolearning
https://redd.it/1ixlqjb
Connecting a Ubuntu server to a webpage using flask

I’ve been trying to connect a python code on a web sever to a webpage, and the main way I’ve tried this was flask. I believe I set everything up correctly, but no luck. If anyone has a good tutorial on how to complete this properly it will be appreciated.

/r/flask
https://redd.it/1iwtccd
Tuesday Daily Thread: Advanced questions

# Weekly Wednesday Thread: Advanced Questions 🐍

Dive deep into Python with our Advanced Questions thread! This space is reserved for questions about more advanced Python topics, frameworks, and best practices.

## How it Works:

1. **Ask Away**: Post your advanced Python questions here.
2. **Expert Insights**: Get answers from experienced developers.
3. **Resource Pool**: Share or discover tutorials, articles, and tips.

## Guidelines:

* This thread is for **advanced questions only**. Beginner questions are welcome in our [Daily Beginner Thread](#daily-beginner-thread-link) every Thursday.
* Questions that are not advanced may be removed and redirected to the appropriate thread.

## Recommended Resources:

* If you don't receive a response, consider exploring r/LearnPython or join the [Python Discord Server](https://discord.gg/python) for quicker assistance.

## Example Questions:

1. **How can you implement a custom memory allocator in Python?**
2. **What are the best practices for optimizing Cython code for heavy numerical computations?**
3. **How do you set up a multi-threaded architecture using Python's Global Interpreter Lock (GIL)?**
4. **Can you explain the intricacies of metaclasses and how they influence object-oriented design in Python?**
5. **How would you go about implementing a distributed task queue using Celery and RabbitMQ?**
6. **What are some advanced use-cases for Python's decorators?**
7. **How can you achieve real-time data streaming in Python with WebSockets?**
8. **What are the

/r/Python
https://redd.it/1ixh4qh
I made a script to download Spotify playlists without login

Repo link: https://github.com/invzfnc/spotify-downloader

What my project does
Hi everyone! I created a lightweight script that lists tracks from a public Spotify playlist and downloads them from YouTube Music.

Key Features

No premium required
No login or credentials required
Metadata is embedded in downloaded tracks
Downloads in higher quality (around 256 kbps)

Comparison/How is it different from other tools?
I found many tools requiring users to sign up for Spotify Developer account and setup credentials before everything else. This script uses the public Spotify API to retrieve track details, so there's no need to login or setup!

How's the music quality?
YouTube Music offers streams with higher bitrate (around 256 kbps) compared to YouTube (128 kbps). This script chooses and downloads the best quality audio from YouTube Music without taking up too much storage space.

Dependencies/Libraries?
Users are required to install innertube, SpotAPI, yt-dlp and FFmpeg for this script to work.

Target audience
Anyone who is looking to save their Spotify playlists to local storage, without wanting to login to any platform, and wants something with decent bitrate (\~256 kbps)

If you find this project useful or it helped you, feel free to give it a star! I'd really appreciate any feedback!

/r/Python
https://redd.it/1ixlsux
Anybody know how to add an Async view to a DRF project .

because simply declaring the @api_view function as async and awaiting statements inside it doesn't work and it clashes with event loops .

/r/djangolearning
https://redd.it/1ix63w0