Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
How to deploy a Django project in 15 minutes with Ansible
In this tutorial I will explain how to deploy a Django project in 15 minutes with Ansible. I will assume that you are a Django developer and you have built and tested a project locally. It’s time to deploy the project on a public server to let users access your awesome application. If you are new in deploying Django on a production server you can read my post Django – NGINX: deploy your Django project on a production server to have a basic introduction on the steps needed. So you need a VPS with an SSH access, then you will access the server, install and configure all necessary software (web server, application server, database server), create a database user, configure Django to use it, copy your Django project on the server, migrate the database, collect static files, trial and error, fix, trial and error, … All this boring stuff will take some good hours that you should definitely spend in a more profitable way, don’t you think? The good news is that you can automate almost all the work needed to go from a vanilla VPS to a fully deployed server hosting your Django project. Follow this tutorial and I’ll … -
HTTPS behind your reverse proxy
We have a setup that looks (simplified) like this: HTTP/HTTPS connections from browsers ("the green cloud") go to two reverse proxy servers on the outer border of our network. Almost everything is https. Nginx then proxies the requests towards the actual webservers. Those webservers also have nginx on them, which proxies the request to the actual django site running on some port (8000, 5010, etc.). Until recently, the https connection was only between the browser and the main proxies. Internally inside our own network, traffic was http-only. In a sense, that is OK as you've got security and a firewall and so. But... actually it is not OK. At least, not OK enough. You cannot trust in only a solid outer wall. You need defense in depth. Network segmentation, restricted access. So ideally the traffic between the main proxies (in the outer "wall") to the webservers inside it should also be encrypted, for instance. Now, how to do this? It turned out to be pretty easy, but figuring it out took some time. Likewise finding the right terminology to google with :-) The main proxies (nginx) terminate the https connection. Most of the ssl certificates that we use are wildcard … -
Building a Custom Block Template Tag
Building custom tags for Django templates has gotten much easier over the years, with decorators provided that do most of the work when building common, simple kinds of tags. -
Continuous Integration and Deployment with Drone, Docker, Django, Gunicorn and Nginx - Part 2
The Introduction This is the second part of a multi-part tutorial covering a simple(ish) setup of a continuous integration/deployment pipeline using Drone.io. Since Part 1, I’ve added a GitHub project outlining a simple Django application that you can use as a reference. In Part 2, we will be adding a publish step to our application’s drone.yml in order to push our image to Docker Hub. Having our image in Docker Hub allows us to easily pull our app’s image onto our staging/production server to allow easy automated deployment. After the publish step we will add a deploy step to the drone.yml that will be responsible for SSHing into an EC2 instance (or wherever your app lives) to pull our newly pushed image and update our app. Let’s get started! Step 1: Publish our app’s image to Docker Hub after a successful pull request. If you recall, our drone.yml should successfully be running our application’s test suite on push and pull events and reporting back to GitHub if our test suite failed or succeeded. After a successful build, we would like to push our app’s Docker image to Docker Hub. Sign up/Log in to Docker Hub Having an account on Docker Hub is free and it … -
Painless Travis CI/CD for Android Project
If you still want your fancy new mobile projects to be continuously tested and pull-requests checked automatically without wanting to spend your entire evening resolving Travis issues, we at Distillery have a solution. The post Painless Travis CI/CD for Android Project appeared first on Distillery. -
Python F-Strings Are Fun!
In python 3.6 we saw the adoption of Literal String Interpolation, or as they are known more commonly, f-strings. At first I was hesitant because... well... we've got multiple string tools already available: one, two = 1, 2 _format = '{},{}'.format(one, two) _percent = '%s,%s' % (one, two) _concatenation = str(one) + ',' + str(two) _join = ','.join((str(one),str(two))) assert _format == _percent == _concatenation == _join Adding f-strings to this mix didn't seem all that useful: _fstring = f'{one},{two}' assert _fstring == _format == _percent == _concatenation == _join I was doubtful, but then I tried out f-strings on a non-trivial example. Now I'm hooked. Be it on local utility scripts or production code, I now instinctively gravitate toward their usage. In fact, f-strings are so useful that going back to earlier versions of Python now feels cumbersome. The reason why I feel this way is that f-strings are concise but easy to understand. Thanks to intuitive expression evaluation I can compress more verbose commands into smaller lines of code that are more legible. Take a look: _fstring = f'Total: {one + two}' # Go f-string! _format = 'Total: {}'.format(one + two) _percent = 'Total: %s' % (one + two) … -
Python F-Strings Are Fun!
In python 3.6 we saw the adoption of Literal String Interpolation, or as they are known more commonly, f-strings. At first I was hesitant because... well... we've got multiple string tools already available: one, two = 1, 2 _format = '{},{}'.format(one, two) _percent = '%s,%s' % (one, two) _concatenation = str(one) + ',' + str(two) _join = ','.join((str(one),str(two))) assert _format == _percent == _concatenation == _join Adding f-strings to this mix didn't seem all that useful: _fstring = f'{one},{two}' assert _fstring == _format == _percent == _concatenation == _join I was doubtful, but then I tried out f-strings on a non-trivial example. Now I'm hooked. Be it on local utility scripts or production code, I now instinctively gravitate toward their usage. In fact, f-strings are so useful that going back to earlier versions of Python now feels cumbersome. The reason why I feel this way is that f-strings are concise but easy to understand. Thanks to intuitive expression evaluation I can compress more verbose commands into smaller lines of code that are more legible. Take a look: _fstring = f'Total: {one + two}' # Go f-string! _format = 'Total: {}'.format(one + two) _percent = 'Total: %s' % (one + two) … -
Two Scoops of Django 1.11 is Out!
When we started the Two Scoops of Django project back in 2012, I never thought it would become a book series. Well, it's turned into just that, and so I'm pleased to announce the "Early Release" or "BETA" release of the Two Scoops of Django: Best Practices for Django 1.11 PDF ebook. Co-authored with Audrey Roy Greenfeld, the 1.11 edition of Two Scoops of Django is filled to the brim with knowledge to help make Django projects better. We introduce various tips, tricks, patterns, code snippets, and techniques that we've picked up over the years. What we didn't know or weren't certain about, once again we found the best experts in the world and asked them for the answers. Then we packed the result into a 530+ page book. What's Next? We'll be adding more material to the 1.11 edition in the near future, hence the term, "Early Release". Everyone who buys the 1.11 ebook from us gets all 1.11 ebook updates. Once we're happy with the ebook, we'll release a print paperback edition, scheduled for May or June. We're selling the book in PDF format, as well as taking pre-orders for the print edition. Order You can purchase the … -
Two Scoops of Django 1.11 is Out!
When we started the Two Scoops of Django project back in 2012, I never thought it would become a book series. Well, it's turned into just that, and so I'm pleased to announce the \"Early Release\" or \"BETA\" release of the Two Scoops of Django: Best Practices for Django 1.11 PDF ebook. Co-authored with Audrey Roy Greenfeld, the 1.11 edition of Two Scoops of Django is filled to the brim with knowledge to help make Django projects better. We introduce various tips, tricks, patterns, code snippets, and techniques that we've picked up over the years. What we didn't know or weren't certain about, once again we found the best experts in the world and asked them for the answers. Then we packed the result into a 530+ page book. What's Next? We'll be adding more material to the 1.11 edition in the near future, hence the term, \"Early Release\". Everyone who buys the 1.11 ebook from us gets all 1.11 ebook updates. Once we're happy with the ebook, we'll release a print paperback edition, scheduled for May or June. We're selling the book in PDF format, as well as taking pre-orders for the print edition. Order You can purchase the … -
Newsletter #6
Welcome to the latest news about Two Scoops Press, Daniel Roy Greenfeld (pydanny), and Audrey Roy Greenfeld (audreyr). Two Scoops of Django 1.11 Early Release Is Out We just released the early release (BETA) of the fourth edition of Two Scoops of Django. This supports the Django 1.11 Long Term Support (LTS) release, which will be maintained until at least April of 2020. In late May, we plan to release the print paperback version. Today you can purchase the early release PDF as well as pre-order the print edition by itself or as a bundle with the PDF. Two Scoops of Django 1.11 in our shop If you have any questions, please read the Two Scoops of Django 1.11 FAQ. Two Scoops Press Legacy Sale For the first time since 2013, we're running a sale! We uncovered two boxes, one that contained several hardcover editions of Two Scoops of Django 1.6, and the other was a set of Two Scoops of Django 1.8 misprints (slight alignment oddities, minor cover coloration issues, or light scuffing). They are on sale for as long as our supplies last. Two Scoops of Django 1.6 Hardcover ($30 off) Two Scoops of Django 1.8 Misprint + … -
Newsletter #6
Welcome to the latest news about Two Scoops Press, Daniel Roy Greenfeld (pydanny), and Audrey Roy Greenfeld (audreyr). Two Scoops of Django 1.11 Early Release Is Out We just released the early release (BETA) of the fourth edition of Two Scoops of Django. This supports the Django 1.11 Long Term Support (LTS) release, which will be maintained until at least April of 2020. In late May, we plan to release the print paperback version. Today you can purchase the early release PDF as well as pre-order the print edition by itself or as a bundle with the PDF. Two Scoops of Django 1.11 in our shop If you have any questions, please read the Two Scoops of Django 1.11 FAQ. Two Scoops Press Legacy Sale For the first time since 2013, we're running a sale! We uncovered two boxes, one that contained several hardcover editions of Two Scoops of Django 1.6, and the other was a set of Two Scoops of Django 1.8 misprints (slight alignment oddities, minor cover coloration issues, or light scuffing). They are on sale for as long as our supplies last. Two Scoops of Django 1.6 Hardcover ($30 off) Two Scoops of Django 1.8 Misprint + … -
Newsletter #6
Welcome to the latest news about Two Scoops Press, Daniel Roy Greenfeld (pydanny), and Audrey Roy Greenfeld (audreyr). Two Scoops of Django 1.11 Early Release Is Out We just released the early release (BETA) of the fourth edition of Two Scoops of Django. This supports the Django 1.11 Long Term Support (LTS) release, which will be maintained until at least April of 2020. In late May, we plan to release the print paperback version. Today you can purchase the early release PDF as well as pre-order the print edition by itself or as a bundle with the PDF. Two Scoops of Django 1.11 in our shop If you have any questions, please read the Two Scoops of Django 1.11 FAQ. Two Scoops Press Legacy Sale For the first time since 2013, we're running a sale! We uncovered two boxes, one that contained several hardcover editions of Two Scoops of Django 1.6, and the other was a set of Two Scoops of Django 1.8 misprints (slight alignment oddities, minor cover coloration issues, or light scuffing). They are on sale for as long as our supplies last. Two Scoops of Django 1.6 Hardcover ($30 off) Two Scoops of Django 1.8 Misprint + … -
Newsletter #6
Welcome to the latest news about Two Scoops Press, Daniel Roy Greenfeld (pydanny), and Audrey Roy Greenfeld (audreyr). Two Scoops of Django 1.11 Early Release Is Out We just released the early release (BETA) of the fourth edition of Two Scoops of Django. This supports the Django 1.11 Long Term Support (LTS) release, which will be maintained until at least April of 2020. In late May, we plan to release the print paperback version. Today you can purchase the early release PDF as well as pre-order the print edition by itself or as a bundle with the PDF. Two Scoops of Django 1.11 in our shop If you have any questions, please read the Two Scoops of Django 1.11 FAQ. Two Scoops Press Legacy Sale For the first time since 2013, we're running a sale! We uncovered two boxes, one that contained several hardcover editions of Two Scoops of Django 1.6, and the other was a set of Two Scoops of Django 1.8 misprints (slight alignment oddities, minor cover coloration issues, or light scuffing). They are on sale for as long as our supplies last. Two Scoops of Django 1.6 Hardcover ($30 off) Two Scoops of Django 1.8 Misprint + … -
SSL/TLS Settings for Django
Let's make your Django project... -
S3 Static & Media Files for Django
Using Amazon Web Services (AWS... -
The luxury of a creative community
The last few months of Evennia development have mainly focused around a series of very nice pull requests from a growing cadre of contributors. I have myself mainly been working away in Evennia's 'devel' branch which will lead up to Evennia 0.7.Contributed goodnessPeople have put in a lot of good work to boost Evennia, both by improving fixing existing things and by adding new features (small selection). Thanks a lot everyone!Contrib: Turn-based combat system - this is a full, if intentionally bare-bones implementation of a combat system, meant as a template to put in your particular game system into.Contrib: Clothing sytem - a roleplaying mechanic where a character can 'wear' items and have this show in their descriptions. Worn items can also be layered to hide that underneath. Had plenty of opportunities for extensions to a given game.Contrib: An 'event' system is in the works, for allowing privileged builders to add dynamic code to objects that fires when particular events happen. The PR is not yet merged but promises the oft pondered feature of in-game coding without using softcode (and notably also without the security of softcode!). A lot of PRs, especially from one user, dealt with cleanup and adherence … -
Django Framework Nedir?
Web Programçılığı Web sayfalarının giderek yaygınlaşması ve kullanıcı ile etkileşmeye ihtiyacının olması nedeniyle CGI(Common Gateway Interface) ile başladığını söyleyebiliriz. CGI yönetemi ile etkileşimli web sayfaları üretmek oldukça pahalı bir iştir. Çünkü sunucuya CGI programının yapacağı her istek geldiğinde, program çalıştırılır. Dış program derlemeli bir dil ile yazılmış veya yorumlanabilir bir dil ile yazılmış olabilir. Yazılımın... Django Framework Nedir? yazısı ilk önce Python Türkiye üzerinde ortaya çıktı. -
Testing django template tags
In this blog post I will give you simple example how to test your template tags in django using django testing tools. Let's get started! How to test templatetags? Let say that you got this template tag under /templatetags/create_header.py in django: from django import template register = template.Library() @register.inclusion_tag('example.html', takes_context=True) def make_header(context): return { 'header_title': context['title'] } This make_header tag will take the title from context and pass it template tag. Right after that example.html will be rendered. If you want to test if this template tag works you can use this: from django.test import SimpleTestCase from django.template import Context, Template class CreateHeaderTemplateTagTest(SimpleTestCase): def test_rendered(self): context = Context({'title': 'my_title'}) template_to_render = Template( '{% load create_header %}' '{% make_header %}' ) rendered_template = template_to_render.render(context) self.assertInHTML('<h1>my_title</h1>', rendered_template) What is happening here? I setup Context instance with a proper variable that will be taken by templatetag. After that I create Template. I used the same syntax to include templatetags inside your html files - they are templates for Django. Below I render a template with context and check if my templatetag renders correctly. And that's all! I have my templatetag tested. Feel free to comment! Cover image from Unsplash under CC0. -
Testing django template tags
In this blog post I will give you simple example how to test your template tags in django using django testing tools. Let's get started! How to test templatetags? Let say that you got this template tag under /templatetags/create_header.py in django: from django import template register = template.Library … -
Release the GitKraken!
The world of information technology is constantly developing and expanding, forcing myself and many other developers to learn new technologies and read smart books on a regular basis. Some people say that a programmer is reaching maturity when he or she starts to learn a second programming language. The post Release the GitKraken! appeared first on Distillery. -
Django ORM operations compared with Peewee
I saw a post in my weekly Python newsletter showing Django users how to execute common queries using SQLAlchemy. Here's the Peewee version. Setup Assume we have a Django model that looks like the following: class Country(models.Model): name = models.CharField(max_length=255, unique=True) continent = models.CharField(max_length=50) In Peewee, our table definition looks almost identical: from peewee import * # Peewee defines __all__, so import * is common practice. class Country(Model): name = CharField(unique=True) # Default max_length of 255. continent = CharField(max_length=50) Because Peewee does not have a singleton, application-wide database configuration, we also need to associate our model with a database. A common convention, when working with more than one table, is to define a base Model class which configures the database. This will save you a lot of typing when you have more than one model: from peewee import * from playhouse.pool import PooledPostgresqlDatabase db = PooledPostgresqlDatabase('my_app') class BaseModel(Model): class Meta: database = db class Country(BaseModel): name = CharField(unique=True) # Default max_length of 255. continent = CharField(max_length=50) To create tables, call the db.create_tables() method, passing in a list of tables. Peewee will re-order the tables so that they are created in the correct order if you have foreign-keys. def create_tables(): db.connect() … -
Django Tips & Tricks #7 - Django Auth Plugin For HTTPie
HTTPie is an alternative to curl for interacting with web services from CLI. It provides a simple and intuitive interface and it is handy to send arbitrary HTTP requests while testing/debugging APIs. When working with web applications that require authentication, using httpie is difficult as authentication mechanism will be different for different applications. httpie has in built support for basic & digest authentication. To authenticate with Django apps, a user needs to make a GET request to login page. Django sends login form with a CSRF token. User can submit this form with valid credentials and a session will be initiated. Establish session manually is boring and it gets tedious when working with multiple apps in multiple environments(development, staging, production). I have written a plugin called httpie-django-auth which automates django authentication. It can be installed with pip pip install httpie-django-auth By default, it uses /admin/login to login. If you need to use some other URL for logging, set HTTPIE_DJANGO_AUTH_URL environment variable. export HTTPIE_DJANGO_AUTH_URL='/accounts/login/' Now you can send authenticated requests to any URL as http :8000/profile -A=django --auth='username:password' -
Python PIP local cache
PIP is the Python Package Manager that allows Python developers and users to easily install Python packages published on the pip remote register by other developers . If you are using the pip manager frequently then you may find this quick tip useful ,where I'll show how you can activate or enable the local cache of pip which is going to boost the download speed of pip packages . The idea behind the pip cache is simple ,when you install a Python package using pip for the first time ,it gets saved on the cache .If you try to download/install the same version of the package on a second time ,pip will just use the local cached copy instead of retrieving it from the remote register . Enabling the local cache of pip Enabling the local cache of pip is fairly simple so let's do it step by step . First open the pip configuration file located at ~/.pip/pip.conf with your preferred text editor . vim ~/.pip/pip.con On Windows %HOME%\pip\pip.ini The configuration file can be also located in ~/.config/pip/pip.conf or in /etc/pip.conf There also legacy per user config files for PIP which are located in : $HOME/.pip/pip.conf on Unix and … -
Python PIP local cache
PIP is the Python Package Manager that allows Python developers and users to easily install Python packages published on the pip remote register by other developers . If you are using the pip manager frequently then you may find this quick tip useful ,where I'll show how you can activate or enable the local cache of pip which is going to boost the download speed of pip packages . The idea behind the pip cache is simple ,when you install a Python package using pip for the first time ,it gets saved on the cache .If you try to download/install the same version of the package on a second time ,pip will just use the local cached copy instead of retrieving it from the remote register . Enabling the local cache of pip Enabling the local cache of pip is fairly simple so let's do it step by step . First open the pip configuration file located at ~/.pip/pip.conf with your preferred text editor . vim ~/.pip/pip.conf Then copy and add this [global] download-cache=/usr/local/pip/cache Next create the folder mkdir -p /usr/local/pip/cache Then give it write access chmod -R 755 /usr/local/pip/cache You can instead use your profile config file ~/.bash_profile So … -
Python and Django Beginner's Pack: books, tutorials, newsletters
I bet a fresh job offer will make anyone a bit happier and more self-confident. Still, most of us had at least a single denied CV or failed interview. If this is the case, consider it as a sort of new experience. This article is intended for a person who'd like to become an intern in a software development company. Here in Django Stars if a candidate fails to pass the interview due to the lack of knowledge, we always provide the list of useful tutorials and books, that can help him or her to improve the coding skills. You don’t need to pass every single course completely. It’s better to start from the very basic tutorials and do a lot of practice(little Python scripts and eventually a simple Django app). And one more very important note: whenever you learn a new concept, data type, class or function, don’t forget to check the official documentation. One day you won’t need anything than the documentation. So far it's a good idea to briefly look it through. So here is our top 10 books and tutorial we recommend for novice programmers or those seeking to become an intern or junior Python/Django Developer: …