Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
How to Create Django Admin List Actions
Django Admin list actions are meant to be used to perform operations in bulk. All Django Admin list views already come with a default action “Delete selected <ModelName>s”. In this short tutorial I will guide you through the steps to create your own list actions. Creating the Action Function Each action in the list is a regular Python function that takes three parameters: the current ModelAdmin, a HttpRequest object (just like a view function) and a QuerySet, which is the list of selected model instances. Those Action Functions can live inside the admin.py module of your app. But if they start to get really big, you can define them outside the admin.py. Following is the skeleton for a Action Function: def my_admin_action(modeladmin, request, queryset): # do something with the queryset my_admin_action.short_description = 'My admin action' Simple Example Consider the following model and model admin: models.py from django.db import models class Book(models.Model): HARDCOVER = 1 PAPERBACK = 2 EBOOK = 3 BOOK_TYPES = ( (HARDCOVER, 'Hardcover'), (PAPERBACK, 'Paperback'), (EBOOK, 'E-book'), ) title = models.CharField(max_length=50) publication_date = models.DateField(null=True) author = models.CharField(max_length=30, blank=True) price = models.DecimalField(max_digits=5, decimal_places=2) pages = models.IntegerField(blank=True, null=True) book_type = models.PositiveSmallIntegerField(choices=BOOK_TYPES) class Meta: verbose_name = 'book' verbose_name_plural = 'books' admin.py … -
How Do I Start Learning Django
If you have done django for any amount of time you have probably gotten this question, and it can sometimes be hard to answer beyond start at the main django site. In this video I attempt to help by giving people a starting point, and some guidance on resources to and how to use. Give it a watch and offer any suggestions, and tweaks you think should be made. How Do I Start Learning Django? -
Here's a Production-Ready Dockerfile for Your Python/Django App
Update (October 29, 2019): I updated this post with more recent Django and Postgres versions, to use Python and pip directly in the container (instead of in a separate virtual environment, which was unnecessary), and switched to a non-root user via Docker instead of uWSGI. -
How to Create Infinite Scroll With Django
In this tutorial I will show you how to implement a very simple infinite scrolling with Django. Basically we will take advantage of Django’s pagination API and a jQuery plug-in. You will find examples using both function-based views and class-based views. Dependencies We don’t need anything other than Django installed in the back-end. For this example you will need jQuery and Waypoints. jQuery 3.1.1 Waypoints After downloading the dependencies, include the following scripts in your template: base.html <script src="{% static 'js/jquery-3.1.1.min.js' %}"></script> <script src="{% static 'js/jquery.waypoints.min.js' %}"></script> <script src="{% static 'js/infinite.min.js' %}"></script> Basic Example This example uses function-based view and I’m simply paginating a list of numbers, which I generate on the fly. urls.py from django.conf.urls import url from mysite.blog import views urlpatterns = [ url(r'^$', views.home, name='home'), ] views.py from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger from django.shortcuts import render def home(request): numbers_list = range(1, 1000) page = request.GET.get('page', 1) paginator = Paginator(numbers_list, 20) try: numbers = paginator.page(page) except PageNotAnInteger: numbers = paginator.page(1) except EmptyPage: numbers = paginator.page(paginator.num_pages) return render(request, 'blog/home.html', {'numbers': numbers}) Here in this view, numbers_list represents a list of 1000 numbers, which I’m breaking down into blocks of 20 numbers per page. After paginating it, I return … -
Django 101 – App Oluşturma ve Model’a Giriş #3
Video Icerisindekiler: – Django için standart ayar düzenlemeleri. – Django App oluşturma. – Migrate ve Makemigrations kavramları. – Classlar için default kavramı ve yeniden düzenleme aşamasında karşılaşılacak sorunların giderilmesi. – Django image için gerekli ayarlamalar. – Django admine erişim. Django 101 – App Oluşturma ve Model’a Giriş #3 yazısı ilk önce Python Türkiye üzerinde ortaya çıktı. -
Django 101 – App Oluşturma ve Model’a Giriş #3
Video Icerisindekiler: – Django için standart ayar düzenlemeleri. – Django App oluşturma. – Migrate ve Makemigrations kavramları. – Classlar için default kavramı ve yeniden düzenleme aşamasında karşılaşılacak sorunların giderilmesi. – Django image için gerekli ayarlamalar. – Django admine erişim. -
Django Likes
# Django Likes Learn how to c... -
Why care about deployment?
Do you know that in Heroku you can enter a single command and have your Django project deployed for you? If there are services that have commoditized deployment, why should you care about nginx, Apache, PostgreSQL, Gunicorn, systemd, and all that, and don’t you spend your time and grey matter on something more useful? I asked the question both to myself and to my readers, and here are my conclusions, in no particular order: Some customers have a policy to use their own infrastructure. Sometimes there is a preference or policy for deploying on infrastructure hosted in a specific country; for example, I have deployed a Greek national project which had to be hosted in Greece. Sometimes it’s cheaper to deploy yourself than to deploy on Heroku, even if you take into account the time required to learn/do it. If you use a deployment service like Heroku you have vendor lock-in. If you deploy yourself you can be more flexible if your needs change. Students learn about compilers and build primitive processors not because they will work in compilers or in hardware, but because the increased understanding of their tools helps them be a better engineer. Likewise, you need to … -
Release 0.11.
We just released LFS 0.11. Changes Adds Django 1.10 support Excludes variants from sitemap Add appending slash to all urls Use F() expressions to update stock amount (#203) Use F() expression to increase use_amount for vouchers (#202) Removes django-pagination (use Django's default one instead) remove STATIC_URL (user static_url tag instead) fix saving properties and variant prices [pigletto] Information You can find more information and help on following locations: Documentation on PyPI Demo Releases on PyPI Source code on bitbucket.org and github. Google Group lfsproject on Twitter IRC -
Quickly and Easily Way to Create a Django Application: BeDjango Starter
BeDjango starter In the following post we will talk about the starter we have released from BeDjango. The decisions we have made, the features we have decided to add and some aspects that we would like to emphasize: Why did we decide to make a starter? Although starting a project in Django is a fairly quick and easy process, after developing several applications, we realized that we used to invest a certain amount of time in each project to implement similar features (registry, basic views, validations, configuration of libraries ...) Therebefore, we decided to invest that time in making a starter that we could easily reuse ... But the thing went out of hand and we created a fairly complete Django base application. Architecture We decided to modify the initial structure of folders and files that gives us django, many of these files are already being used by the community: We would like to point out that we have added a 'logic.py' file where we place all the logic of code, in this way we gain modularity and improve the way we have to perform the tests, doing these directly against code and not only with access to views. We have also been … -
Logging verbosity in django management commands
Django has a command line --verbosity 0/1/2/3 option, but it only has influence on some of django's internal output. It does not affect generic python logging levels. For management commands it can be handy to control the log level of the console output. First thing to look at, then is the logging setup. I normally have something like this in my settings.py: LOGGING = { ... 'handlers': { 'console': { 'level': 'DEBUG', 'class': 'logging.StreamHandler', 'formatter': 'verbose' }, 'logfile': { 'level': 'INFO', 'class': 'logging.FileHandler', 'formatter': 'verbose', 'filename': os.path.join( SOMEWHERE, 'var', 'log', 'django.log'), }, }, 'loggers': { '': { 'handlers': ['console', 'logfile'], 'propagate': True, 'level': 'INFO', }, 'django.request': { 'handlers': ['console', 'logfile'], 'propagate': False, 'level': 'ERROR', # WARN also shows 404 errors }, ... some more specialised loggers ... } } A console handler that prints everything of log level DEBUG and higher and a logfile that starts at INFO (or WARN). Loggers: the '' one is the root logger. Everything that's not handled elsewhere ends up here. A level of INFO filters out all the DEBUG level messages. The django.request logger is one I normally configure separately as everything of level WARN and higher is normally logged to sentry. And I … -
Django 101 – Veri Tabani Tablolarinin Analizi (ER Diyagrami) #2
Video Icerisindekiler: – Projede kullanilacak ER tablosunun incelenmesi – Relations kavrami (Many To One · One To One · Many To Many) – Django Model dokumantasyonu -
Django 101 – Veri Tabani Tablolarinin Analizi (ER Diyagrami) #2
Video Icerisindekiler: – Projede kullanilacak ER tablosunun incelenmesi – Relations kavrami (Many To One · One To One · Many To Many) – Django Model dokumantasyonu -
Fast Application Development with Django Starters
If you have been working in the software industry for many years you will probably know that one of the principles in development is reuse. Specifically, in Django we have some design philosophies: Less Code Quick Development Don’t repeat yourself Usually developers apply these principles to the code they write, so when they begin a new application they begin to import all the modules needed for the construction and to make all the configuration required. When constructing an application from scratch they always have to repeat a long sequence of almost identical steps, and wrongly, most developers think that there is not an alternative to this behaviour. There is a much better alternative and it is provided by Django. We call it “Starters” and in the next technical posts we will explain how to get your own Starter, but in this one, we will talk about the advantages that Starters bring for our products and clients. The starters are templates of different base projects which have a set of predefined features that we can implement in a record time to begin to develop the prototype or the final solution for our clients. We obtain a set of very interesting benefits … -
Fast Application Development with Django Starters
If you have been working in the software industry for many years you will probably know that one of the principles in development is reuse. Specifically, in Django we have some design philosophies: Less Code Quick Development Don’t repeat yourself Usually developers apply these principles to the code they write, so when they begin a new application they begin to import all the modules needed for the construction and to make all the configuration required. When constructing an application from scratch they always have to repeat a long sequence of almost identical steps, and wrongly, most developers think that there is not an alternative to this behaviour. There is a much better alternative and it is provided by Django. We call it “Starters” and in the next technical posts we will explain how to get your own Starter, but in this one, we will talk about the advantages that Starters bring for our products and clients. The starters are templates of different base projects which have a set of predefined features that we can implement in a record time to begin to develop the prototype or the final solution for our clients. We obtain a set of very interesting benefits … -
Python Datetime Get Month Ranges
Every once and a while you nee... -
How To Install Django Debug Toolbar
The Django Debug Toolbar is a configurable set of panels that display various debug information about the current request/response and when clicked, display more details about the panel's content. For the installation of the Django Debug Toolbar you need to have a django project where you can use pip in a Virtual Environment or without them. If you wan’t use pip, you can get the code of this component from here (https://github.com/jazzband/django-debug-toolbar) and put it in your django project path. But is more easy the pip installation and we will focus on this. For installation we recommend use the virtual env and execute this command: pip install django-debug-toolbar The configuration of this component is simple, but because most of the configuration must be done in the core of the settings of the project, we recommend to do it independently. First, in your general project urls.py, enter this code: from django.conf import settings from django.conf.urls import include, url if settings.DEBUG: import debug_toolbar urlpatterns += [ url(r'^__debug__/', include(debug_toolbar.urls)), ] Take care with the “imports” because it’s possible that you duplicate some of this. In the settings.py we enter our independent conf for this component, like this: DEBUG = True if DEBUG: INTERNAL_IPS … -
Django 101 – Proje Kurulumu #1
Video Icerisindekiler: – Onerilen dosyalama yapisi. – Onerdigim dokumantasyon kaynaklari. – Proje dizini olusturulmasi ve gerekliliklerin eklenmesi. – Django projesi olusturulmasi. -
Django 101 – Proje Kurulumu #1
Video Icerisindekiler: – Onerilen dosyalama yapisi. – Onerdigim dokumantasyon kaynaklari. – Proje dizini olusturulmasi ve gerekliliklerin eklenmesi. – Django projesi olusturulmasi. -
MVC Nedir ? (Django – MVT)
Model-View-Controler yani MVC yapisi ve kullanim amaci nedir. Django icin MVT yapisi ve calisma mekanizmasi. -
MVC Nedir ? (Django – MVT)
Model-View-Controler yani MVC yapisi ve kullanim amaci nedir. Django icin MVT yapisi ve calisma mekanizmasi. -
Virtualenv Nedir ve Nasıl Kullanılır
Bu ilk videom olduğu için bazı hatalarım olduğunu fark etmemek mümkün değil. Şimdilik bu hatalarla bu video yayınlamaya ve sonraki içeriklerde daha dikkatli olmaya çalışacağım. Virtualenv Nedir ve Nasıl Kullanılır yazısı ilk önce Python Türkiye üzerinde ortaya çıktı. -
How To Install Django-LocalFlavor
Package of the week: LocalFlavor Have you ever had to develop a web application with unique fields depending on the country to which the user is focused or to which the user belongs? The solution to these problem is a package called Django-localflavor, as the same documentation says: ‘’django-localflavor is a collection of assorted pieces of code that are useful for particular countries or cultures’’. It is a very easy to use package that we have used in BeDjango with great results and we will try to explain it briefly Installation This package is really easy to install: pip install django-localflavor Then add ‘localflavor’ to your INSTALLED_APPS setting: INSTALLED_APPS = ( # ... 'localflavor', ) Countries fields Currently the package has specific fields for the following list of countries, although they accept new issues and PR in their repository in github Argentina (ar) Austria (at) Australia (au) Belgium (be) Bulgaria (bg) Brazil (br) Canada (ca) Switzerland (ch) Chile (cl) China (cn) Colombia (co) Czech Republic (cz) Germany (de) Denmark (dk) Ecuador (ec) Estonia (ee) Spain (es) Finland (fi) France (fr) Great Britain (gb) Greece (gr) Hong Kong (hk) Croatia (hr) Hungary (hu) Indonesia (id) Ireland (ie) Israel (il) India (in) … -
Tips and Tricks for Improved Django Security: published
In this article we shall discuss a point to which we give little importance when we are beginning to programme our application and which, with little details, we can improve significantly. Security! Nowadays, there are many methods through which a website may find itself in risk of being attacked, in the following link we can see the TOP 10 most common risks according to OWASP. Next, we'll give you a few pieces of advice about security without mentioning those shown on the official django website. Wappalyzer is an extension which identifies the software running on our website, which allows some bots to exploit known bugs before we can patch our website, for which reason it is advisable to protect our website from this type of extension. In our case, django is detected by the “csrfmiddlewaretoken” whose name we can change, and whose information we can amplify, by following the subsequent guide hide-django-from-wappalyzer. One of the strengths of django is the administration panel, which we can reach by using the default url */admin. A way of hiding this panel and avoiding brute-force attacks is to change this url, which is as a simple as modifying the file urls.py and substituting: # Default … -
Django + Chart.js
Learn how to integrate Charts....