Django community: Community blog posts RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
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. AWS have added many managed services that help ease the process of hosting web applications on AWS. The most important addition to the AWS stack (for us) was undoubtedly Amazon RDS for Postgres, launched in November 2013. As long-time advocates for Postgres, this addition to the AWS suite was the final puzzle piece necessary for building an AWS infrastructure for a typical Django app that requires little to no manual management. Still, the suite of AWS tools and services is immense, and configuring these manually is time-consuming and error-prone; despite everything it offers, … -
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() … -
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() … -
Build GraphQL Web APIs with Django Graphene
On the previous tutorial we have introduced GraphQL to build Web APIs .In this tutorial we are going to build a real world example web application with Django ,which makes use of GraphQL and its Python implementation ,Graphene . Tutorial Parts : Building Better Django WEB APIs with GraphQL Tutorial Build GraphQL Web APIs with Django Graphene Lets start by creating a new virtual environment and install required packages including django , Head over to your terminal and enter : virtualenv graphqlenv source graphqlenv/bin/activate This will create a new virtual environment and activate it . Next install django and graphene packages with pip pip install django pip install graphene_django You can also install graphiql_django which provides a user interface for testing GraphQL queries against your server . pip install graphiql_django Next lets create a Django project with a single application : python django-admin.py startproject inventory . cd inventory python manage.py startapp inventory Open settings.py and add inventory and graphenedjango to installedapps array : INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'graphene_django', 'inventory' ] Then create your database : python manage.py migrate Create models Open inventory/models.py then add : # -*- coding: utf-8 -*- from __future__ import unicode_literals from … -
Build GraphQL Web APIs with Django Graphene
In this tutorial part we will see a real world example of how to build a GraphQL API with Django Graphene -
Setup Git & A Github Repo
Git is a version control syste... -
Our Tech
This is what drives our busine... -
Building Better Django WEB APIs with GraphQL : Tutorial Part 1
GraphQL is a new technology of building APIs created and open sourced ,in February 2015 ,by Facebook so how does it differ from the old way of building HTTP Rest APIs ? GraphQL allows you to query your server for the exact data that you want ,no less no more ,sending just one request even for multiple related models . So the first difference ,when using the classic Rest APIs ,in many situations you either get less data ,in this case you will need to send more requests to retrieve all data you need ,or you get more data than what you actually need ,which consumes your server and your network resources . The second difference ,when requesting some model data from a Rest endpoint ,if you need the related models data you usually end up with more requests to multiple endpoints . Thanks to GraphQL ,the client can describe and define exactly the requested data in a JSON format and the server takes care of sending the data in the same format . Lets take a simple example to understand how GraphQL works . Suppose we have a Django web application with two models ,products and families : class … -
How To Exclude node_modules Directory When Running collectstatic Command in Django
If you use npm or yarn to install frontend packages inside your Django project, you may notice, that when you run python manage.py collectstatic command, it ends up collecting huge amounts of files. That's because by default, collectstatic grabs all content of static directories inside the project, including thousands of ... Read now -
django-cabinet – A media library for Django
django-cabinet – A media library for Django django-cabinet is a media library for Django implemented while trying to write as little code as possible to keep maintenance at a minimum. At the time of writing the projects consists of less than 1000 lines of code (excluding tests), but still offers hierarchical folders, downloads, images with primary point of interest (courtesy of django-versatileimagefield) and drag-drop uploading of files directly into the folder view. You’ll find more details and screenshots at Github and Read the Docs. -
Django Kullanıcıları Yasaklama – DjangoBan
Django’da kayıtlı kullanıcıları yasaklamak için DjangoBan paketini kullanabiliriz. Uyumluluk Django 1.9+ Python 3.x + Kurulum pip install DjangoBan Ayarlar Django settings.py girip, INSTALLED_APPS bölümüden ban app’ını ekleyin. #settings.py INSTALLED_APPS = [ ... 'ban', ] Django settings.py girip Middleware bölümüne ban.middleware.BanManagement katmanını ekleyin. MIDDLEWARE = [ ... 'ban.middleware.BanManagement', ] Database İşlemleri python manage.py makemigrations python manage.py migrate Örnek Banlanmış Kullanıcı Kullanımı Admin panel üzerinden, basit şekilde kullanıcıyı yasaklayabilirsiniz. Django Ban – Template Template sayfasını özelleştirmek için, uygulamanızının templates klasörüne “ban.html” oluşturup değişiklik yapar iseniz o değişiklik yansıyacaktır. -
Making a Rails App Move Faster: A Tale of Lessons Learned
my experience, most performance improvement tasks take the following form: “This request is working too slow. We have to make it faster.” Sound familiar? In general, to find and remove all mistakes and nonsense parts in the program code, the request itself and all related actions must be thoroughly examined. On this occasion, however, we had to come up with a completely different approach. The post Making a Rails App Move Faster: A Tale of Lessons Learned appeared first on Distillery. -
Create First Project and Start Development Server
Now that we have installed required development tools including Django framework ,it's time for the first real step to start building our real estate app while learning Django essentials from scratch . Django framework includes a bunch of very useful utilities to create and manage projects that can be accessed from a Python file called django-admin.py that becomes available when we first installed Django . In this section we are going to see how to : Create a new project Setup and create the project database Start the development server Create a new Django project Creating a new Django project is easy and quick so open your terminal or command prompt then enter : $ django-admin.py startproject django_realestate This command will take care of creating a bunch of necessary files for the project . Executing the tree command in the root of our created project will show us the files that were created . . ├── django_realestate │ ├── __init__.py │ ├── settings.py │ ├── urls.py │ └── wsgi.py └── manage.py init is the just the Python way to mark the containing folder as a Python package which means a Django project is a Python package . settings.py is the … -
Create First Project and Start Development Server
Now that we have installed required development tools including Django framework ,it's time for the first real step to start building our real estate app while learning Django essentials from scratch . Django framework includes a bunch of very useful utilities to create and manage projects that can be accessed from a Python file called django-admin.py that becomes available when we first installed Django . In this section we are going to see how to : Create a new project Setup and create the project database Start the development server Create a new Django project Creating a new Django project is easy and quick so open your terminal or command prompt then enter : $ django-admin.py startproject django_realestate This command will take care of creating a bunch of necessary files for the project . Executing the tree command in the root of our created project will show us the files that were created . . ├── django_realestate │ ├── __init__.py │ ├── settings.py │ ├── urls.py │ └── wsgi.py └── manage.py init is the just the Python way to mark the containing folder as a Python package which means a Django project is a Python package . settings.py is the … -
Encodings — part 1
Has a UnicodeEncodeError ever got on your nerves? I think it has happened to pretty much everyone. I thought it’s a good time to start demystifying this mystery, and to have fun while doing it. You are probably familiar with the famous hello program, which does nothing but print “Hello, world!” Now we are going to create the bon program, which prints “Bon appétit!” Here it is, but don’t type it in or copy/paste it: import sys sys.stdout.write("Bon appétit!\n") We could have written it with a single print statement, but for several reasons I prefer this version. Now, I told you to not type in this program or copy/paste it. Instead, we are going to create it by writing down the bytes that comprise it. The file bon.py, like any file, is a series of bytes. These bytes represent the characters in the file. The first character is “i”, which is represented by the byte 105; the second one is “m”, represented by 109; and so on. You can find the table for all characters (except é) at Wikipedia. In order to create the file, we will use another Python program. Here it is. You can copy and paste that …