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
What are your "glad to have met you" packages?

What are packages or Python projects that you can no longer do without? Programs, applications, libraries or modules that have had a lasting impact on how you develop with Python.
For me personally, for example, pathlib would be a module that I wouldn't want to work without. Object-oriented path objects make so much more sense than fiddling around with strings.

/r/Python
https://redd.it/1dsyi19
GitVis -- visualize your git commits locally

What my project does

GitVis is a tool written in Python that allows you to visualize your local commits for the last 6 months from a given date. The visualization is done in a manner similar to GitHub and GitLab, providing a familiar and intuitive interface.

GitHub: https://github.com/aldinash/gitvis

PyPi: https://pypi.org/project/gitvis/

Target Audience

I built this project for fun

Comparison

There is an implementation of this tool in Go. I decided to create a similar project in Python and continue developing a CLI for visualizing the local Git workflow.

/r/Python
https://redd.it/1dso9ao
Flask Blog tutorial: How to only get posts from current user?

Hello all, I am trying to create a workout tracker app in Flask using the the blog tutorial as a starting point.
I know the blog posts in the tutorial are supposed to be public to all users, but I am trying to figure out how to just show the current user their own posts and not the posts from another registered user. I have tried a few different methods but I have been unsuccessful so far. My latest implementation will only show one post per user and if one user has made 2 posts, the second post will be shown to the another logged in user.

Here's a snippet from my blog.py. Not sure if I'm on the right track:

@bp.route("/")

@login_required

def index():

"""Show all the posts, most recent first."""

db = get_db()

posts = db.execute(

"SELECT p.id, train, workout, date, duration, sets, reps, weight, created, author_id, username"

" FROM post p JOIN user u ON p.author_id = u.id"

" WHERE p.id = ?"

" ORDER BY created DESC",

(g.user['id'\],),

).fetchall()

return render_template("blog/index.html", posts=posts)

Please see the rest of my code here:
https://github.com/frenchfrysamurai/myFlaskProject

/r/flask
https://redd.it/1dsza2l
Seeking Feedback: Building DRF-like Views for Flask as a Resume Project - Will It Add Value?

I am thinking of projects that I can show off in my resume. But I am finding it really hard to find a good project idea. Recently I got an idea like why don't I build packages. I am thinking making views for flask like DRF's list/create/retrieve/update/delete views which will also provide authentication and permission handling just like DRF. I am thinking of using Marshmallow for data serialization/de serialization and sqlalchemy for ORM as requirements for this project. What do you think? will this add any value to my resume ? Will people use it if I publish it in PYPI ? Any suggestions? Or what are projects that I can work on for my resume. Should I try to contribute in others open source project instead ?

/r/flask
https://redd.it/1dslgsc
What are your "wish I hadn't met you" packages?

Earlier in the sub, I saw a post about packages or modules that Python users and developers were glad to have used and are now in their toolkit.

But how about the opposite? What are packages that you like what it achieves but you struggle with syntactically or in terms of end goal? Maybe other developers on the sub can provide alternatives and suggestions?

/r/Python
https://redd.it/1dt95io
Cookies not being set in firefox

Like the title states I have a /login endpoint where I set cookies, in this case a access_token and a refresh_token, however when I go to firefox open up my next js app and login, the cookies do not appear inside the the cookie storage. How ever inside the network request you can see the tokens are being set



https://preview.redd.it/zpr39vuyjs9d1.png?width=1445&format=png&auto=webp&s=d64b7fb8f69519d213e39b79122603f30df22b07

https://preview.redd.it/e9u8cfx1ks9d1.png?width=1449&format=png&auto=webp&s=6318c81530a2a96ede5488412c5ec7f7aa3294cf

Does something special have to be done for the tokens to be set in Firefox?? They are set in other browsers such as chrome, and edge. Below I will paste the code related to my /login endpoint and my main entry point for the flask app. Any help is appreciated this has been driving me nuts for hours.

from flask import Flask, jsonify
from sqlalchemy import text
from config import Config
from extensions import db, jwt
from blueprints import authbp
from dotenv import load
dotenv
from flaskmigrate import Migrate
from flask
cors import CORS

loaddotenv()


def create
app():
 

/r/flask
https://redd.it/1dseeha
I made a quiz about my favourite module in the Python standard library: Asyncio

Hey everyone, a few weeks ago I made a quiz about the Python programming language for new Python developers to spark conversation. I've now gone and made another quiz about asyncio, my favourite module in the Python standard library. We use this extensively at work and it is the reason we can continue to use Python in the face of a very competitive space for concurrent programming.


Here's the new quiz: quiz

/r/Python
https://redd.it/1dt97sg
I created my first GUI Python app.

I have developed an application that allows users to download audio and videos from YouTube. You can check out the project on my GitHub: https://github.com/khalildim/youtube_downloader.
I'm looking for some advice and feedback to improve the app.

/r/Python
https://redd.it/1dt7ik7
For some reason everything seems to be working but the email is not being sent.

For some reason everything seems to be working but the email is not being sent.

Could someone help me figure out what is causing the bug?

I just want to add I am not getting an error anywhere. The email is just not being sent.

To run the email I am using EMAIL_USERNAME which is equal to gmail username and EMAIL_PASSWORD is equal to the app password.

I get to the route in /registration_verification_code/<username_db> by redirecting after registering and logging in assuming registration_confirmation_email is False.

(Here is where the error occurs.)

email_login_confirmation/routes.py https://pastebin.com/baHPsdN9

registration_verification_code.html (uses bootstrap) https://pastebin.com/5QH3ab39

renderform.html (uses bootstrap) *https://pastebin.com/U4uruBAV*

*models.py*
*https://pastebin.com/Qj4vyVgt*

*config.py*

*https://pastebin.com/7RDUBEBQ*

\_\_init\_\_.py
https://pastebin.com/P4xN1G4w

app.py (code below for app.py)

from app import createapp
app = create
app()

To run the code in powershell in vsc for windows I type after starting the env.

$env:FLASKDEBUG='True
$env:FLASK
ENV='dev'
flask run

 I can add requirements.txt if anyone wants.

Thank you for the help.



I may have solved this I will update if I have.

/r/flask
https://redd.it/1ds5rbo
Confused about how to structure my RESTful APIs

I am building an Inventory Management System with Django Rest Framework. Two of the models I have are: Inventory and Product.

The tutorials/courses that I watched only show basic views/viewsets: list and detail. But now working on the frontend Dashboard page, I realized I have to show:

Count of:
Total Products
Total stock value
Low stock items
Table of:
Top 5 products by quantity
Top 5 products by value

These are not the typical views that I've worked with. My questions:

1. Do I create separate views (or viewset actions) for these specific queries
2. On the frontend make multiple API calls to these routes, i.e.,
/api/inventory/low_stock_items_count
`/api/inventory/total_stock_value_count`
/api/inventory/total_products_count etc. etc.

What is the actual approach to doing this? Because when I was writing regular Django with templates, I had one context dictionary for the dashboard view that contains all my data.

/r/django
https://redd.it/1dtfmv8
Deploying flask application on IONOS Server


Hello everyone,

I'm having trouble deploying my Flask application on my IONOS web hosting server (SFTP) and hoping someone here has experience with this and can help me out.

This is the first time I've put something I've built online, so please don't assume I have much background knowledge.

Problem Summary:
I have a Flask web application that runs perfectly on my local computer using Visual Studio Code and the command `python app.py`. I have uploaded the entire project structure to my IONOS server, but I am encountering various issues with the configuration and execution of the application.

Current Configuration:
- Server: IONOS Web Hosting
- Project Directory: `/ProjectFile`
- Virtual Environment: `venv` in the project directory
- Uploaded Files:
- `app.py` (main Flask application file)
- `requirements.txt` (list of dependencies)
- `dispatch.fcgi` (FastCGI script)
- `.htaccess` (Apache configuration file)
- `wsgi.py` (WSGI entry point)

Error Messages:
When accessing the domain, I get a `500 Internal Server Error` message. Here are the steps I have taken so far:

1. Set up the virtual environment and install dependencies:
```bash
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
```

2. Created `dispatch.fcgi`:
```python
#!/usr/bin/env

/r/flask
https://redd.it/1dtjvr0
can anybody tell me whats the diff? indentation?

/r/django
https://redd.it/1dtpxtm
VS Code setup for Django/Jinja2 templates??

Hey guys, seeking some tips on how to property setup auto completion/intellisense and formatting in VS Code. I tried q couple of extensions and changed a few settings, but it never get in a good state IMO, either formatting sucks or I don't have the proper auto completes...

What is your setup, any insight you be great 🔥

/r/django
https://redd.it/1dtrc58
Best tool to minimize html?

I am using django-webpack-loader to bundle and minimize my css and js. What should I use to minimize my html?

/r/django
https://redd.it/1dtoh6l
Need help with s3 and django-storages

Hello everyone, this is my first time working with any cloud storage. I am following this tutorial here from Michael Herman, and there were a few discrepancies right from the beginning.

First, when I tried running the collectstatic command, I got this error:

botocore.exceptions.ClientError: An error occurred (AccessDenied) when calling the PutObject operation: Access Denied

I looked up a bit, and apparently you have to set AWS_DEFAULT_ACL = None and doing that fixed it.

So now my static files were being uploaded to the s3 bucket when I ran collectstatic.

But when I visited the webpages, the static images and stylesheets were not getting fetched as expected.

I tried many different things at this point, but none of them worked. I typed the s3 object url in the browser and this was the error I was getting:

<Error>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<RequestId>419CX01JK1CAKYCS</RequestId>
<HostId>
rB7y8qLl5a5G0I1LVx2lexUbJpcvnrdKIMZ3AVq69C81B3j4BRWZwLq5THNLINwSv6q5HFSAednN1yq2tRCQ6THuxEn+S/Kj
</HostId>
</Error>

Now the next logical thing I did was to make all the bucket objects as public. The tutorial doesn't do this and I'm not sure if its a bad thing or not? Anyone

/r/django
https://redd.it/1dtnhtd
PyCon US 2024 | All recorded content now available!

All sessions on the Main Stage at PyCon US 2024 are now posted for your viewing pleasure as well as:

* Our amazing Keynote speakers [u/kjaymiller](https://fosstodon.org/@kjaymiller@mastodon.social), Kate Chapman, [@brainwane](https://fosstodon.org/@brainwane@social.coop), and [@simon](https://fosstodon.org/@simon@simonwillison.net) ️
* Lightning talks
* The Python Steering Council
* Tutorials
* Sponsor Presentations

Check it out on the official PyCon US YouTube channel:

* [https://www.youtube.com/@PyConUS](https://www.youtube.com/@PyConUS)
* Full Playlist: [https://www.youtube.com/watch?v=OH3C5a2uAWA&list=PL2Uw4\_HvXqvYhjub9bw4uDAmNtprgAvlJ](https://www.youtube.com/watch?v=OH3C5a2uAWA&list=PL2Uw4_HvXqvYhjub9bw4uDAmNtprgAvlJ)

/r/Python
https://redd.it/1dtxqph
ORM is hard

First project ever. Spent a couple of weeks finalising the model. Getting complex queries right is such a pain. Keep getting lost in the syntax. Joins don't work. Column names are strings sometimes, sometimes not. The syntax is maddening. I get things right in my mind though.

I'm pulling data out of querysets into lists so that I can use normal string methods instead of annotating querysets and getting stuck. How much of a performance penalty is that in the real world?

/r/djangolearning
https://redd.it/1dtw2p2
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/1ds3fbp
How can I enable connection pooling in Django REST Framework with PostgreSQL without using PgBouncer?

I do not want to use PgBouncer because there are no proper articles on how to enable it. Could you please share articles on how to do this without using PgBouncer

/r/django
https://redd.it/1du7h8k