Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Creating Smaller Docker Images Part #4: Static Binaries
This is the fourth post in a series on making smaller Docker images: static binaries. In the first post I talked about how to create smaller images by writing better Dockerfiles. In the second post I talked about how to squash layers using docker-squash to make smaller images. In the third post I wrote about how to use Alpine Linux as a smaller base image. In this post I'll examine the ultimate when it comes to making smaller images: static binaries. What if your app didn't have any dependencies and didn't need anything at all except the app itself? This is what static binaries achieve. [...] -
Creating Smaller Docker Images Part #4: Static Binaries
This is the fourth post in a series on making smaller Docker images: static binaries. In the first post I talked about how to create smaller images by writing better Dockerfiles. In the second post I talked about how to squash layers using docker-squash to make smaller images. In the third post I wrote about how to use Alpine Linux as a smaller base image. In this post I'll examine the ultimate when it comes to making smaller images: static binaries. What if your app didn't have any dependencies and didn't need anything at all except the app itself? This is what static binaries achieve. [...] -
Django 1.11+ django.contrib.auth Class Based Views - Part 2 - Password Change and Reset
Since we can log in and logout what about managing our password? Learn the power of using the builtin Generic Class Based Views now in django.contrib.auth. They are simple to use once you know about them.Watch Now... -
Domain Name for Django Development Server
Isn't it strange that browsing the web you usually access the websites by domain names, however, while developing a Django website, you usually access it through IP address? Wouldn't it be handy to navigate through your local website by domain name too? Let's have a look what possibilities there are to access the local development server by a domain name. Access via IP Address You probably know the following line by heart since the first day of developing with Django and can type it with closed eyes? (myenv)$ python manage.py runserver When you run a management command runserver, it starts a lightweight Django development server which by default listens to HTTP requests on your local machine's port 8000, whereas by default, HTTP websites are running on the 80 and HTTPS websites are running on 443. Enter http://127.0.0.1:8000 in a browser and you can click through your Django project. Note that this is a local address and it is not accessible from other devices in the network. Other people accessing the same address from their computers will see what is provided by web servers on their own machines, if any web server is running there at all. Each device in a … -
Markdown Cheatsheet
A quick reference to using Mar... -
Ask Vitor #3: Mocking Emails
Phillip Ahereza asks: I’m writing unit tests for my django app and I was wondering if there are any packages for mocking email or if there is any way I could mock sending and receiving of emails. Answer Basically what Django does when you run your test suite is switch your EMAIL_BACKEND to django.core.mail.backends.locmem.EmailBackend, so to prevent your application from sending emails during the tests execution. While using this backend, all emails sent are stored in the outbox attribute of the django.core.mail module. Let’s see one example on how you can use it to test the email outputs and so on. urls.py from django.conf.urls import url from mysite.core import views urlpatterns = [ url(r'^send/$', views.send, name='send'), ] views.py from django.http import HttpResponse from django.core.mail import send_mail def send(request): email = request.GET.get('email') if email and '@' in email: body = 'This is a test message sent to {}.'.format(email) send_mail('Hello', body, 'noreply@mysite.com', [email, ]) return HttpResponse('<h1>Sent.</h1>') else: return HttpResponse('<h1>No email was sent.</h1>') This is a simple view that expects a querystring parameter named email with a valid email address. If the email value fulfill our view requirements, an email is sent to this address. If the email is invalid or no email … -
AJAXify Django Forms
## **Guide is currently under ... -
Django Framework ve Güvenlik
Merhaba arkadaşlar bu yazımda Django Framework ve Güvenlik konusunu ele alacağız. Bildiğiniz üzre Django, python programlama dili ile yazılmış olan bir web uygulaması geliştirme çatısıdır. Biz geliştiricilere sağladığı esneklik, kolaylıklığı ve hızı eklediğimiz de bizim için önemli olan bir web uygulaması geliştirme çatısıdır. Geliştiriciler için tercih edilmesinin en büyük nedeni yapmış olduğumuz web uygulamalarını daha... Django Framework ve Güvenlik yazısı ilk önce Python Türkiye üzerinde ortaya çıktı. -
Django AbstractUser ile Genişletme
User Modelini Genişletme Merhabalar, OneToOneField ile user modelini genişlettik. Fakat AbstractUser kullanarak genişletmek daha akıllıca bir hareket olacaktır. Yeni bir proje başlatıyorsanız, varsayılan Kullanıcı Modeli sizin için yeterli olsa bile özel bir kullanıcı modeline bir şekilde ihtiyaç duyacaksınız. AbstractUser model, varsayılan kullanıcı modeliyle aynı şekilde davranıyor, ancak ihtiyaç ortaya çıkarsa kullanmanız yeterlidir. Model.py giriş yapalım. [crayon-595ebcd4d5558309387880/] User adında... Django AbstractUser ile Genişletme yazısı ilk önce Python Türkiye üzerinde ortaya çıktı. -
Django AbstractUser ile Genişletme
User Modelini Genişletme Merhabalar, OneToOneField ile user modelini genişlettik. Fakat AbstractUser kullanarak genişletmek daha akıllıca bir hareket olacaktır. Yeni bir proje başlatıyorsanız, varsayılan Kullanıcı Modeli sizin için yeterli olsa bile özel bir kullanıcı modeline bir şekilde ihtiyaç duyacaksınız. AbstractUser model, varsayılan kullanıcı modeliyle aynı şekilde davranıyor, ancak ihtiyaç ortaya çıkarsa kullanmanız yeterlidir. Model.py giriş yapalım. #model.py from django.db import models # Özel kullanıcı from django.contrib.auth.models import AbstractUser class User(AbstractUser): #Avatar'ı ekledik. Avatar = models.CharField(max_length=50)User adında bir oluşturduk. User modelini default olarak django’nun algılaması için settings.py’e “AUTH_USER_MODEL” değişkeni ile belirtmemiz gerekiyor. Settings.py giriş yapalım. #settings.py #app : Uygulama adı #User : model adı AUTH_USER_MODEL = 'app.User'Admin panele girdiğimizde “kullanıcılar” bölümü silinmiş olacaktır. Yeni user modelini, admin panele ekliyelim. admin.py giriş yapalım. #admin.py from django.contrib import admin from .models import User from django.contrib.auth.forms import UserChangeForm, UserCreationForm from django.contrib.auth.admin import UserAdmin from django import forms # Kullanıcı seçme ekranı class MyUserChangeForm(UserChangeForm): class Meta(UserChangeForm.Meta): # Yeni model model = User class MyUserAdmin(UserAdmin): # Yeni Form form = MyUserChangeForm # Görünmesi gerekenler list_display = UserAdmin.list_display+('Avatar',) # Yeni alanlar fieldsets = UserAdmin.fieldsets + ( (None, {'fields': ('Avatar',)}), ) #Yeni Kullanıcı oluşturma sınıfı class MyUserCreationForm(UserCreationForm): class Meta(UserCreationForm.Meta): # Yeni model model = User def clean_username(self): username = … -
Django Code Review
We want to help solve problems... -
The Purpose of Business
Businesses exist to create val... -
The Purpose of Business
Businesses exist to create val... -
Try Django 1.11 has landed.
Learn Django Basics in the Try... -
Django Modellere Giriş
Django Modelleri ile kısaca veritabanı işlemleri yaparız. Django kullanıcı ne SQL tabloları oluşturur ne sorgularını yaparlar. Bunların hepsini bize django yapacaktır Şimdi siz rahatınıza bakın onlar sorguları ile uğraşsınlar 🙂 biraz bu mantığa daynan bir yapısı vardır. Bu makalede Models giriş niteliğinde bilgiler olacaktır, Models tam olarak ne işe yarar neler yaparız gibi soruları cevaplayacağım.... Django Modellere Giriş yazısı ilk önce Python Türkiye üzerinde ortaya çıktı. -
Django Modellere Giriş
Django Modelleri ile kısaca veritabanı işlemleri yaparız. Django kullanıcı ne SQL tabloları oluşturur ne sorgularını yaparlar. Bunların hepsini bize django yapacaktır Şimdi siz rahatınıza bakın onlar sorguları ile uğraşsınlar biraz bu mantığa daynan bir yapısı vardır. Bu makalede Models giriş niteliğinde bilgiler olacaktır, Models tam olarak ne işe yarar neler yaparız gibi soruları cevaplayacağım. Model için temel bilgileri taşıyan bilgilerdir dikkatli okuyunuz. Django Veritabanı Yapılandırılması Django ön tanımlı olarak PostgreSQL, MySQL, SQlite ve Oracle desteği ile gelir. Veritabanı yapılandırılması proje klasöründeki settings.py içerisinden yapılır. Bu dosyanın DATABASES bölümü aşşağıdaki gibidir :DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 'USER':'', 'PASSWORD':'', 'HOST':'', 'PORT':'', } }Buradakı verileri açıklayalım : ENGINE : Herhangi bir veritabanı sistemini kullanacaksanız burada belirtmeniz gerekiyor. Örneğin : Postgresql_psycopg2,mysql,sqlite3,oracle gibi veriler yazılabilir. Burada ön tanımlı olarak “django.db.backends.sqlite3” yazan Sqlite3 sistemi olduğunu belirtmektedir. NAME : Bağlantı kurulacak veritabanı ismi yazılır. Önemli bir nokta konum belirtilerek isim yazılmalıdır. “os.path.join(BASE_DIR, ‘db.sqlite3’)” şu yapı ana dizindeki db.sqlite3 verisi olduğunu belirtmektedir. USER : Veritabanı kullanıcı adı var ise yazılacak bölümdür. PASSWORD : Veritabanı şifresi var ise yazılacak bölümdür. HOST : Eğer veritabanı farklı bi yerde barınıyorsa, ip bilgisi yazılır. PORT : Farklı port üzerinde çalışalacaksa port bilgisi yazılır. Eğer port bilgisi yazılmazsa … -
Django 1.11+ django.contrib.auth Class Based Views - Part 1
This is the first in a long series on creating a CryptoCurrency management site, but first we need to lock things down so people can't see all of our stuff. So we will start by setting up our app and logging in and out. We will do this with the new Class Based Views in django.contrib.auth system.Watch Now... -
Django Tips #20 Working With Multiple Settings Modules
Usually, it’s a good idea to avoid multiple configuration files, instead, keep your project setup simple. But that’s not always possible, as a Django project starts to grow, the settings.py module can get fairly complex. In those cases, you also want to avoid using if statements like if not DEBUG: # do something.... For clarity and strict separation of what is development configuration and what is production configuration, you can break down the settings.py module into multiple files. Basic Structure A brand new Django project looks like this: mysite/ |-- mysite/ | |-- __init__.py | |-- settings.py | |-- urls.py | +-- wsgi.py +-- manage.py First thing we want to do is to create a folder named settings, rename the settings.py file to base.py and move it inside the newly created settings folder. Make sure you also add a __init__.py in case you are working with Python 2.x. mysite/ |-- mysite/ | |-- __init__.py | |-- settings/ <-- | | |-- __init__.py <-- | | +-- base.py <-- | |-- urls.py | +-- wsgi.py +-- manage.py As the name suggests, the base.py will provide the common settings among all environments (development, production, staging, etc). Next step now is to create … -
Django, GraphQL & React - part one
Hello! Welcome back after a little break - I recently started working on a project that uses GraphQL. Thant's why I thought that it will be the best to show you how to build a simple application using these tools. Let's get started! First, comes this idea - what application can I … -
Go Live with Django & Heroku
Make your Django project live ... -
Deploy Django Project to Heroku
Make your Django project live ... -
Django bulk_update without upsert
Postgres 9.5 brings a fantastic feature, that I've really been looking forward to. However, I'm not on 9.5 in production yet, and I had a situation that would really have benefitted from being able to use it. I have to insert lots of objects, but if there is already an object in a given "slot", then I need to instead update that existing object. Doing this using the Django ORM can be done one a "one by one" basis, by iterating through the objects, finding which one (if any) matches the criteria, updating that, or creating a new one if there wasn't a match. However, this is really slow, as it does two queries for each object. Instead, it would be great to: * fetch all of the instances that could possibly overlap (keyed by the matching criteria) * iterate through the new data, looking for a match * modify the instance if an existing match is made, and stash into pile "update" * create a new instance if no match is found, and stash into the pile "create" * `bulk_update` all of the "update" objects * `bulk_create` all of the "create" objects Those familiar with Django may recognise that … -
Managing your AWS Container Infrastructure with Python
We deploy Python/Django apps to a wide variety of hosting providers at Caktus. Our django-project-template includes a Salt configuration to set up an Ubuntu virtual machine on just about any hosting provider, from scratch. We've also modified this a number of times for local hosting requirements when our customer required the application we built to be hosted on hardware they control. In the past, we also built our own tool for creating and managing EC2 instances automatically via the Amazon Web Services (AWS) APIs. In March, my colleague Dan Poirier wrote an excellent post about deploying Django applications to Elastic Beanstalk demonstrating how we’ve used that service. -
Don't include social engineering in penetration tests
I’m not a fan of including social engineering – spearphishing, calls to support tickets, office visits – as part of penetration tests. These activities are risky, and often involve borderline and outright inappropriate behavior. Further, they tend not to produce useful results. I encourage you to explicitly forbid social engineering attacks in your pentest scopes. Instead, try simulating the kinds of compromises that social engineering attacks lead to, with an emphasis on detection and response. -
django-debreach + DRF = sadness
I sunk 4 hours of my life into this problem yesterday so I thought I might post it here for future frustrated nerds like myself. If you're using django-debreach and Django REST Framework, you're going to run into all kinds of headaches regarding CSRF. DRF will complain with CSRF Failed: CSRF token missing or incorrect. and if you're like me, you'll be pretty confused since I knew there was nothing wrong with the request. My token was being sent, but it appeared longer than it should be. So here's what was happening and how I fixed it. Hopefully it'll be useful to others. Django-debreach encrypts the csrf token, which is normally just fine because it does so as part of the chain of middleware layers in every request. However, DRF doesn't respect the csrf portion of that chain. Instead it sets csrf_exempt() on all of its views and then relies on SessionAuthentication to explicitly call CSRFCheck().process_view(). Normally this is ok, but with a not-yet-decrypted csrf token, this process will always fail. So to fix it all, I had to implement my own authentication class and use that in all of my views. Basically all this does is override SessionAuthentication's enforce_csrf() …