Django and Python | Tips and utilities
61 subscribers
24 photos
14 links
Download Telegram
Check if your file name is an image with mimetypes.


#python #django
🔥1
When dealing with the Django signals framework I use to use the instance method refresh_from_db in combination with a "stop" statement in order to stop the signal from being triggered.

#django #python
🔥1
Channel name was changed to «Django and Python| Tips and utilities»
In some cases, I don't want to spend time registering models when I am in an early development phase of a Django project.

I let Django register my models in the admin site on the fly.

#python #django
👏2
When dealing with many models in a Django app and with a lot of help text for each field, I create a "help text" module to keep my code cleaner.

Also, I standardize the max length of the character fields.

#python #django
Create a PDF from a blog post using Django Template Framework and xhtml2pdf.

Interested?

Check the live code: https://github.com/ramiboutas/englishquiz

Check the demo: https://www.englishstuff.online/blog/advanced/25-phrasal-verbs-with-get/
I am proud of what I created with Django and htmx! :)

https://www.englishstuff.online/

There is still a lot of to do, but it is (for me) enough to be proud of.
2
In Django sometimes I need to create a helper function to read file content (maybe located in a s3 bucket) and save it temporarily in the file system.
1
If you need to change a virtual environment variable from your .env file, you can use this code.

Place it under utils/env.py or in a similar module.

#django #python #djangotricks
1
If feels so good when you have to write less code.

In this example I simplified a lot my django model forms but using python class inheritance.
👏21
Group your Django apps in a directory.


If you are curious, check how:

https://www.ramiboutas.com/articles/django-group-your-apps-in-a-directory/
1
Order your apps in the Django admin site by adding a prefix to the verbose_name attribute in the app config.
2