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
Django agGrid

Hello r/django,

I'm new to Django and would like to get some advise on a project I'm working on.

My table returns a list of hotels with CRUD functionality via modal forms utilizing django forms. The problem is that scrolling is quite slow (overflow-auto was used to make the table scrollable). I intend to use agGrid to output the list, but it only accepts JSON response. Is it a bad idea to have a separate view for handling JSON response? Is it possible to just create an app using drf and have separate app for html views that output the forms and send the post to the view created from drf?

Here's the html table.

<tbody>
{% for hotel in hotels %}
<tr class="border-b dark:border-gray-700">
<th scope="row" class="px-4 py-2 font-medium text-gray-900 whitespace-nowrap dark:text-white">{{ hotel.name }}</th>
<td class="px-4 py-2 whitespace-nowrap">{{ hotel.rating }}</td>


/r/djangolearning
https://redd.it/13mytbu
I want to build a chatbot with Openai API

Hello guys! Does someone have a tutorial or an example?

/r/flask
https://redd.it/13n0hly
This media is not supported in your browser
VIEW IN TELEGRAM
[R] Video Demo of “Drag Your GAN: Interactive Point-based Manipulation on the Generative Image Manifold”

https://redd.it/13mpxbw
@pythondaily
Sunday Daily Thread: What's everyone working on this week?

Tell /r/python what you're working on this week! You can be bragging, grousing, sharing your passion, or explaining your pain. Talk about your current project or your pet project; whatever you want to share.

/r/Python
https://redd.it/13nd675
JIRA <3 Django ?

Is there a way to use JIRA as a bug-reporting system for the users of my Django app ? How can I do this integration ? If not - how is everyone handling bug reporting from user side for SaaS apps ?

/r/django
https://redd.it/13nk7mj
Discover Awesome Python projects

www.awesomepython.org is an app with useful, hand-picked packages and libraries

Each project links to its GitHub repo and makes it easy to discover new trending projects, quality established projects and other statistics (e.g. that auto-gpt is growing by \~13k stars per week!)

screenshot

I posted this last year and have added a lot of new functionality since then: category filtering, similar libraries, pypi & arxiv links, an "importance" score (based on the OpenSSF criticality score), and many more useful libraries

It has many recently created libraries too, for example, it's got a comprehensive list of repos in the large language model/chatgpt category: www.awesomepython.org/?c=llm

The full list, code and json data is available on GitHub: https://github.com/dylanhogg/awesome-python

Package/library suggestions welcome, I hope you find it useful

/r/Python
https://redd.it/13nrf87
Simple flask get and post messenger

Hi there am new in flask and I want to create a Flask server that handles GET and POST requests. In this case, the server will wait for a specific GET request and won't respond until it receives a corresponding POST request. Once the POST request is received, the server will use the data from the POST request to respond to the pending GET request.

Simply put, the server waits for a POST request to arrive before answering a specific GET request with the data from the POST request
Look i make the script i ask if there more professional way to do it look
''from flask import Flask, request, jsonify
import threading

app = Flask(__name__)
pending_request = None
event = threading.Event()

@app.route('/data', methods=['GET', 'POST'])
def handle_data():
global pending_request

if request.method == 'GET':
event.wait() # Wait until the event is set (POST request received)
data = pending_request
pending_request = None
event.clear() # Reset the event for the next round
return jsonify({'status': 'Data received', 'data': data})



/r/flask
https://redd.it/13nle2r
Serve static files with compression/decompression?

I have a flask app that will serve static swf and mp3 files. Some of them are ~25 each. They are served as a batch. What options do I have to speed up the transfer via compression on flask side and definition at the endpoint?

/r/flask
https://redd.it/13nzge5
Most efficient way of using cursor connections

I have a database and have multiple endpoints where each endpoint makes a specific DB query of its own. Now if we open and close connections on each endpoint, that would be too resource heavy.

Is there a way where we can open a connection for each user once and let him visit all the endpoints without re-opening/closing cursors? Like so:

conn = connection.open()

@app.route('/')
def home():
# some db execution

@app.route('/new', methods='POST')
def new():
# some other db execution

# and then close the cursor once a user is not there any longer

or we need to open and close cursors on every endpoint?

If there is a library to do so, then too I would like to know how it is handling cursors


# Edit:

I just learned about connection pooling. That answers everything

/r/flask
https://redd.it/13mnpro
How do I avoid MySQL/SQLAlchemy connection timeouts on a production server?

I have a Flask application server running on A2Hosting. An SQLAlchemy engine is created upon application launch:

engine = create_engine("mysql+pymysql://{}:{}@{}:{}/{}".format(
db_uname, db_pswd, db_host, "3306", db_name))

As a consequence, every day I'll be greeted with this error in my logs when I access the Website:

sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (2006, "MySQL server has gone away (ConnectionResetError(104, 'Connection reset by peer'))")

I deduce that this error is probably due to a connection timeout, although I cannot confirm this.

It's only mildly annoying because when I try my backend call again, everything proceeds as normal.

Obviously, it'd be nice if this didn't happen when the app is released to the public.

What should I do instead?

/r/flask
https://redd.it/13l8fw7
How to add another kernel to jupyter lite online notebook?

I am not a coder. I am just taking data science classes. I want to use Jupyter on my own. I have a problem. I want the python 3 kernel, but jupyter only has 2 other kernels. Im trying to import a module but the other 2 kernels don't have it. thanks.

/r/JupyterNotebooks
https://redd.it/13ocaxe
How can I have two 'static' folders for 2 containers (each running a flask app) behind the same reverse proxy?

I have a docker, with 3 containers. One running nginx and two python containers serving with uwsgi and each having a flask app.

Before only one of the python containers needed to access the /static/ folder but now they both need to but /static/ is mapped to one of them in nginx.conf. How can I make it so each python container can access their own static folder with :

{{ urlfor('static', filename='script.js') }}

this is the nginx.conf:

http {
    server {
        include uwsgi
params;
        include mime.types;
        servertokens off;
        proxy
hideheader X-Powered-By;
        add
header Content-Security-Policy "default-src 'self' cdn.jsdelivr.net code.jquery.com; frame-ancestors 'self'; form-action 'self';";
        addheader X-Frame-Options SAMEORIGIN;
        add
header X-Content-Type-Options nosniff;
        addheader Referrer-Policy "no-referrer";
        add
header Permissions-Policy "geolocation=(),midi=(),sync-xhr=(),microphone=(),camera=(),magnetometer=(),gyroscope=(),fullscreen=(self),payment=()";




/r/flask
https://redd.it/13od98c
Monday Daily Thread: Project ideas!

Comment any project ideas beginner or advanced in this thread for others to give a try! If you complete one make sure to reply to the comment with how you found it and attach some source code! If you're looking for project ideas, you might be interested in checking out Al Sweigart's, "The Big Book of Small Python Projects" which provides a list of projects and the code to make them work.

/r/Python
https://redd.it/13oakho
Raspberry Pi Debuts a Code Editor for Young People: "Python is the preferred coding language for beginners (particularly young people), as it’s the most intuitive language utilized by professionals. For this reason, Raspberry Pi’s Code Editor uses Python (specifically the standard library and P5)."
https://www.reviewgeek.com/150725/raspberry-pi-debuts-a-code-editor-for-young-people/

/r/Python
https://redd.it/13o040f
Cuid2 - Secure, collision-resistant ids optimized for horizontal scaling and performance. Next generation UUIDs.

I've just released v2.0.0 of my cuid2 python port. The original cuid2 package comes from JS world by ParallelDrive. They have a lot of the reasons to use Cuid2 posted in their repo, including

Secure: It's not feasible to guess the next id, existing valid ids, or learn anything about the referenced data from the id. Cuid2 uses multiple, independent entropy sources and hashes them with a security-audited, NIST-standard cryptographically secure hashing algorithm (Sha3).

Collision resistant: It's extremely unlikely to generate the same id twice (by default, you'd need to generate roughly 4,000,000,000,000,000,000 ids (sqrt(36^(24-1) 26) = 4.0268498e+18) to reach 50% chance of collision.

Horizontally scalable: Generate ids on multiple machines without coordination.

Offline-compatible: Generate ids without a network connection.

URL and name-friendly: No special characters.

Fast and convenient: No async operations. Won't introduce user-noticeable delays. Less than 5k, gzipped.

But not too fast: If you can hash too quickly you can launch parallel attacks to find duplicates or break entropy-hiding. For unique ids, the fastest runner loses the security race.

You can find the source code of my package here: https://github.com/gordon-code/cuid2

And install it with

$ pipx install cuid2


When doing my own research on UUID replacements, I came across another of

/r/django
https://redd.it/13nyey6
DRF views across multiple tables

I've written an API using DRF to help with tracking multiple deployments of an app with different configurations, so I have about half-a-dozen models with many-to-many relationships between each. Here's an example of one of my models:

class Package(models.Model):
engine = models.ForeignKey(Engine, on_delete=models.CASCADE)
ruleset = models.ForeignKey(Ruleset, on_delete=models.CASCADE)
configuration = models.ForeignKey(Configuration, on_delete=models.CASCADE)
created = models.DateTimeField(auto_now_add=True)

Each of the Engine, Ruleset and Configuration models has a name field. I was able to get the API running very quickly, the problem is that DRF expects that if I create a new package entry that I should supply the ID numbers for each of engine, ruleset and configuration. Is there a way I can allow the user / client to supply the name for each instead?

Similarly, when accessing in the browser, the view for Package just shows the ids of the other pieces and the form wants me to pick from a list of ids instead of names. Do I need to write a custom view and form myself to be able to see

/r/django
https://redd.it/13om7y0