Login

Tag "django"

Snippet List

Mask sensitive data from logger

This will help to secure the sensitive secrets, token, api keys, etc from logger. As we know there is security issue when we include the sensitive information to the logger in case logger got leaked/hacked. Before: ``` INFO ('192.168.1.1', 33321) - "WebSocket /ssh?token=abcdefg&width=20&heigh20" ``` After: ``` INFO ('192.168.1.1', 33321) - "WebSocket /ssh?token=********&width=20&heigh20" ```

  • django
  • security
  • logging
  • logger
Read More

Python Django CRUD Example Tutorial

Hey Friends, In this quick example, let's see django tutorial & crud example with mysql and bootstrap. step by step explain django crud operations with mysql backend. step by step explain django crud operations with mysql bootstrap. let’s discuss about django crud operations with mysql database. Read more... [https://tuts-station.com/python-django-crud-example-tutorial.html](https://tuts-station.com/python-django-crud-example-tutorial.html)

  • django
  • python
  • crud
Read More

Read image url as base64

Read the image url as base64 in django, this snippet usefull if you using the `django-easy-pdf` to solve this issue https://github.com/nigma/django-easy-pdf/issues/53 Usage example: ``` <img src="{{ profile.photo.url|read_image_as_base64 }}"> ```

  • django
  • image
  • templatetags
  • base64
  • imagepreview
Read More

Django Standard API Response Middleware for DRF

As you can see, if you using django-rest-framework, you will found many different response format. This middleware to solve all of these problems with Standard API Response. All HTTP Response status stored into json response, not in HTTP Status (because mobile application, like android can't fetch the response body when HTTP Status >= 400).

  • middleware
  • django
  • api
  • django-rest-framework
Read More

a better Django Slug Unique Generator

let say the user chooses the name "Elsa Frozen" now his slug would be "Elsa-Frozen-5" it means 4 other people have used the same header now he can go to url: "your website.com/Elsa-Frozen-4" to see other people's Post

  • django
  • slug
  • url
Read More

Calculating Maintainability Index for a whole project

With this command you can calculate the maintainability index for your whole project. In your settings you have to add a dictionary called `RADON_MI_SETTINGS`. It could be like this: ```python RADON_MI_SETTINGS = { 'paths': ['projectname'], 'exclude': 'projectname/some_app/some_file.py', 'ignore': 'migrations,tests', } ``` I had to add following packages: ``` radon==3.0.1 progress==1.5 plotly==3.7.0 GitPython==2.1.11 ``` Following commands are available: * `python manage.py calculate_maintainability_index` Only display the maintainability index of the project. The average from every file is build by using the logical lines of code per file. * `python manage.py calculate_maintainability_index --init` Go through every commit filtered by their commit_message (is set to “bump version” currently) and calculate the maintainability index for the whole project. This creates a file with the history. * `python manage.py calculate_maintainability_index --showhistory` Display the history of the maintainability_index in a graph in your browser. * `python manage.py calculate_maintainability_index --commit` Calculate the current maintainability_index and append it to your history. Commit your edited history file. * `python manage.py calculate_maintainability_index --fail` Calculate the current maintainability_index and raise an Error, if it is lower than the last entry in your history. Useful for use in an automated pipeline. Hints: * radon has a problem with large lists and dictionaries. If you have a file with a list or dictionary with more than 100 entries, you should exclude it. * To initialize your history you should change the commitmessage filter to something, that suits your needs. Created by Martin Becker at [Jonas und der Wolf GmbH](https://www.jonasundderwolf.de)

  • django
  • command
  • git
  • maintainability
Read More

Django nginx sendfile example

Use nginx sendfile (X-Accel-Redirect) function to serve files but pass traffic through django. Can be used to serve media files only to logged-in users.

  • django
  • media
  • sendfile
  • nginx
Read More

213 snippets posted so far.