Django community: Community blog posts RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
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.... -
How to Crop Images in a Django Application
Cropping images is a fairly common use case in a Web application. For example, some applications let you upload a profile picture. In addition, it usually also let you crop and resize the image for a better result. Unfortunately, when dealing with image processing we need to install a few dependencies, both in the front-end and in the back-end. In this tutorial I will demonstrate how to upload an image, display a preview in a modal, crop the image and finally upload it and save in the server. If you are not familiar with file upload in Django, check this post for a quick reference: How to Upload Files With Django. Installing Dependencies In the following example I will be using: Python 3.6.0 Django 1.10.5 Pillow 4.0.0 jQuery 3.1.1 Cropper v3.0.0-beta Within your project directory or virtualenv, install Pillow: pip install Pillow I know, I know… Sometimes installing Pillow is a nightmare. If you face any problem installing it locally, please refer to the Pillow’s Installation Guide. The jQuery utility to crop images in the Web browser can be downloaded here. Or if you prefer to use it’s pure JavaScript version, download Cropper.js here. But please note that in the … -
Tracking the Results of Cron Jobs
Every Django website needs some automatic background tasks to execute regularly. The outdated sessions need to be cleaned up, search index needs to be updated, some data needs to be imported from RSS feeds or APIs, backups need to be created, you name it. Usually, if not all the time, those regular tasks are being set as cron jobs. However, when some task is run in the background, by default, you don't get any feedback whether it was successfully completed, or whether it crashed on the way. In this post I will show you how I handle the results of cron jobs. In a Django project, all those tasks are usually implemented as management commands. For each such command I write a short bash script, that will call the management command with specific parameters and will print the verbose output to a log file. Let's say my project structure is like this on a remote server: /home/myproject├── bin├── include├── lib├── public_html├── backups├── project│ └── myproject├── scripts└── logs A virtual environment is created in the home directory of myproject linux user. The Django project itself is kept under project directory. The scripts directory is for my bash scripts. And the logs … -
Build Facebook messenger bots with Python and Django
Throughout this tutorial ,we are going to see how to build a Facebook messenger bot using Python and Django framework . The Facebook messenger platform is one of the biggest platforms for messaging on the Internet in these days . If you are a business and your have a Facebook page that it might be a good idea to provide your users with an automatic method to get some answers such as the frequently asked questions that get asked all the time by customers but you can also build more advanced bots that use artificial intelligence (AI) . Here is a list of the best messenger bots Also watch this video from CNNMoney which talks about how Messenger Bots can replace customer service for brands You'll learn how to build a simple Facebook bot step by step .The bot will not use any advanced AI algorithms but only a simple IF based statements so you need to have some knowledge about Python language and Django framework . Creating a Facebook app A Facebook bot is just another type of Facebook apps so we need to create a Facebook app for our bot . Simply go to Facebook developers website then … -
Django deployment webinar starting soon
Today on 16:00 UTC I’m hosting a webinar. Deploying Django: From zero to production in 20 minutes. I’m sorry about the late notice. I’ve announced it on many places and it has generated quite some interest, but it occured to me that some people who are monitoring this blog might not see it elsewhere. See you on the webinar. The post Django deployment webinar starting soon appeared first on Django deployment. -
Django Admin and Celery
A weird race condition Some background: We have a model that is edited only via the Django admin. The save method of the model fires a celery task to update several other records. The reason for using celery here is that the amount of related objects can be pretty big and we decided that it is best to spawn the update as a background job. We have unit and integration tests, the code was also manually tested, everything looked nice and we deployed it. On the next day we found out that the code is acting weird. No errors, everything looked like it has worked but the updated records actually contained the old data before the change. The celery task accepts the object ID as an argument and the object is fetched from the database before doing anything else so the problem was not that we were passing some old state of the object. Then what was going on? Trying to reproduce it: Things are getting even weirder. The issues is happening every now and then. Hm...? Race condition?! Let's take a look at the code: class MyModel(models.Model): def save(self, **kwargs): is_existing_object = False if self.pk else True super(MyModel, self).save(**kwargs) … -
You Sould do Weird Stuff in Django
Out of the ordinary things are the times that we grow the most as developers. However, a lot of times we don't do enough weird things when we write our software. I would encourage you to try that odd idea that you have been messing with in your head that you aren't sure you can do. Ironically you will grow more as a developer from that than your day to day getting stuff done development I am not sure why I ever really thought about this, but give a watch to what keyed me in on this thought. You Should Do Weird Stuff in Django -
Install Django on Mac OS or Linux
# Install Django & Virtualenv ...