Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Ionic 3 : Create a cross platform mobile application with Python Django and Django Rest Framework (DRF)
In this two parts tutorial ,we are going to recreate our previous Ionic 3 product inventory manager application ,which used a local SQLite database ,to use a Python Django backend . The application we'll be creating in this tutorial uses Ionic 3 as a frontend ,Django as a backend and Django Rest Framework to create Rest API which will be consumed by Ionic . It's a simple product inventory management application which shows you many Django concepts such as How to create a Django project from scratch . How to create a Django app . How to model and create database models . How to migrate your database . How to generate the Admin web interface to create ,update ,delete and view database records . How to create a super user . How to generate a browsable and documented Rest API with Django Rest Framework . What is Django ? Django is a Python based web framework which encourages rapid development which is used by many web developers create web applications .It has a clean and pragmatic design which can help ypu create complete prototypes in a hours .Django packages or apps for organization and reuse .You can either create … -
Django vs Flask in 2017
The Python language has many great frameworks for building web applications among them Django and Flask . Both frameworks are gaining more popularity steadily in time and there are no signs they are becoming less popular or obsolete even if the web has known many important changes since the data they have been created . Django was created in 2005 while Flask was created in 2010 .Today we are in 2017 which means Django is 12 years old and Flask is 7 years old .They are both extremely popular frameworks to build web applications with Python but they are so different in principle from each other .While Django follows a battery included approach making it a full packed ,complete and an opinionated framework ,on the other hand Flask is a micro framework ,an un-opinionated framework that let you choose what tools you can use for building a web app from the ORM to the templating engine . In this post we'll discuss some points you might want to consider if you need to learn Django or Flask or maybe both ? and which framework you should consider using to build your next project ? and in which situations ? They … -
Django vs Flask in 2017
The Python language has many great frameworks for building web applications among them Django and Flask . Both frameworks are gaining more popularity steadily in time and there are no signs they are becoming less popular or obsolete even if the web has known many important changes since the data they have been created . Django was created in 2005 while Flask was created in 2010 .Today we are in 2017 which means Django is 12 years old and Flask is 7 years old .They are both extremely popular frameworks to build web applications with Python but they are so different in principle from each other .While Django follows a battery included approach making it a full packed ,complete and an opinionated framework ,on the other hand Flask is a micro framework ,an un-opinionated framework that let you choose what tools you can use for building a web app from the ORM to the templating engine . In this post we'll discuss some points you might want to consider if you need to learn Django or Flask or maybe both ? and which framework you should consider using to build your next project ? and in which situations ? They … -
Django 1.11 : Create super user for Admin back office
After you successfully created your first project with Django 1.11 ,created an app and migrated your SQlite database .It's time to access the admin interface or back office generated automatically by Django which you can use to create ,delete ,edit and list your database tables data . You can visit the admin interface from http://localhost:8200/admin You'll be presented with a form to enter your username and password credentials .If you enter any values you'll get a message : Please enter the correct username and password for a staff account. Note that both fields may be case-sensitive. Since you have no staff user created yet but don't worry this can be fixed with one command . Head over to your terminal ane run : python manage.py createsuperuser You'll be prompted for a username and a password (twice) ,enter them and hit Enter . Next run your local server again : python manage.py runserver Then visit your admin interface http://localhost:8200/admin and enter your credentials then hit Login button . You should be successfully logged in . -
Django 1.11 : Create or start your first project
Django is a Python based framework which offers developers all they need to create a web apps and websites in a clean ,rapid and a pragmatic way . How do I start a Django project ? is the first quesion which gets asked by a beginner Django developer so lets answer it . Tutorial requirements To better grasp this tutorial ,you need to have some Python experience and also how to work with Linux bash commands or Windows command prompt if you are using Windows for development . Development requirements Before you can create or start a Django project you need to have you development environment setup . Here is what you need to install before continuing with this tutorial : Python 2.7.x or 3.4.x PIP package manager Virtualenv Django Code editor (Sublime,gedit etc.) If you are using a Linux/MAC machine you should have Python already installed . You can check that running the following command on your terminal python -v If you don't have Python installed head over to Python download page PIP is a Python package manager used to easily install Python packages and their dependencies .You can install PIP using curl utility curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py" python … -
How to Configure Mailgun To Send Emails in a Django Project
In this tutorial you will learn how to setup a Django project to send emails using the Mailgun service. Previously I’ve published in the blog a post about how to configure SendGrid to send emails. It’s a great service, but they don’t offer free plans anymore, nowadays it’s just a 30 days free trail. So, I thought about sharing the whole email setup with a better option to get started. Mailgun is great and super easy to setup. The first 10,000 emails you send are always free. The only downside is that if you don’t provide a payment information (even though you are only going to use the first 10,000 free emails), there will be some limitations, such as requiring to configure “Authorized Recipients” for custom domains, which pretty much makes it useless, unless you know beforehand the email addresses you will be sending emails. Anyway, let’s get started. Initial Setup Go to www.mailgun.com and create a free account. Sign in with your Mailgun account, click on Domains and then Add New Domain. I will setup the Mailgun service for a domain I own, “www.bottlenose.co”. For the setup, it’s advised to use the “mg” subdomain, so you will need to … -
8 Reasons to Affirm Your Legacy in a Blog
-
Django efficient implementation of Amazon s3 and Cloudfront CDN for faster loading.
Django by default to store the files in your local file system. To make your files load quickly and secure we need to go for any third party storage systems. AWS s3 is one of the storage service for the Internet. It is designed to make web-scale computing easier for developers. django has a package called django-storages which can be used to store the files in the amazon s3. and serve them from its cloud front service. Implementing django-storages with amazon s3 as storage service in your django application: To implment django-storages in your django application you need to follow the following steps. 1. Install django-storages: We can install django-storages with the following command. pip install django-storages 2. Keep storages in your installed apps. INSTALLED_APPS = ( ... 'storages', ... ) 3. Change your DEFAULT_FILE_STORAGE setting in your settings.py file: Django by default comes with a setting called DEFAULT_FILE_STORAGE which deals with file storage. By default its value is 'django.core.files.storage.FileSystemStorage'. By keeping this value to DEFAULT_FILE_STORAGE, django, by default tries to store the files on your local machine. To store your files in amazon s3 just change that value to 'storages.backends.s3boto3.S3Boto3Storage' DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage' 4. Configure your AWS ACCESS_KEY … -
Interview with Andrew Godwin about deployment
This is an interview I took from Django core developer Andrew Godwin about deployment. Recorded in DjangoCon EU 2017, Florence, Italy. https://djangodeployment.com/wp-content/uploads/2017/05/godwin.mp3 ANT: Hello everyone! This is Antonis from djangodeployment.com. It’s 5 April 2017 and I am at the European Django Conference in Florence. I am sitting with Andrew Godwin, who is a Django core developer mostly known as the creator of migrations and now Django Channels, and we are going to have a little chat about deployment. Hello Andrew! AND: Hello! It’s lovely to talk to you! ANT: Thanks! Some years ago you tried to create a deployment service which was called epio. So, could you tell me a little bit more about that? AND: Of course! As a bit of background history, we’re talking quite a few years now when Heroku was just for Ruby at the time, and so I was sitting in DjangoCon US and me and a friend had the idea to, why not do Heroku for Python?, which of course was an idea common to several startups at that time. We took on the challenge of making a platform-as-a-service, which is what Heroku of course is. I think it was two or three … -
How to Deploy a Django Application on RHEL 7
In this tutorial, you will learn how to deploy a Django application with PostgreSQL, Nginx, Gunicorn on a Red Hat Enterprise Linux (RHEL) version 7.3. For testing purpose I’m using an Amazon EC2 instance running RHEL 7.3. Recently I had to deploy an existing Django project running on Ubuntu 16.04 to a new environment, RHEL 7.3. It gave me some headache because I don’t have much server administration skills and I wasn’t familiar with Security Enhanced Linux (SELinux) distributions, so I thought about sharing the details of the deployment so it could help someone in the same position I was. If you are just getting started with Django deployment, and doesn’t have a good reason to be using RHEL, I suggest you use Ubuntu instead. It requires less configuration, and the process is fairly easier than using RHEL. Perhaps you could check this past tutorial: How to Deploy a Django Application to Digital Ocean. Anyway, for this tutorial I will deploy the following Django application: github.com/sibtc/urban-train. It is just an empty Django project to demonstrate the deployment process. So, every time you see urban-train, change it for your project name. Initial Setup First, let’s install all the needed resources and … -
3 Reasons to Upgrade to the Latest Version of Django
When considering a website upgrade, many business stakeholders probably think about the frontend, i.e., how the website looks or the features users interact with. Perhaps less often considered is the importance of upgrading the backend; that is, the databases, applications, and servers powering all the behind-the-scenes activity. Infrastructure support and upgrades are necessary but often performed as a separate project from any improvements to design or user experience, rather than as part of a holistic update project. -
DroidShoter — Making Application Screenshots With Various Resolutions, Using The Same Device
As you know, there are many different devices using Android. As a result, there are also an incredible number of displays with different combinations of resolution and pixel density to take into account, which makes the entire development process significantly more complex. At one point, we at Distillery decided to make the testing process on various displays easier and avoid running the application on different devices and virtual machines. After performing a thorough analysis of the problem, the solution became obvious — it is one which could be implemented using Adb and only one connected device. As a result, we managed to develop cross-platform utility software that automatically saves application screenshots with various parameters of the display without any need to change the source code of the application (it also works with various emulators and virtual machines). After running the utility software, the developer gets several screenshots of the application, which reflect the appearance of it on devices with different configurations. The developer can use these screenshots in order to find application artifacts and to analyze the level of layout optimality. The post DroidShoter — Making Application Screenshots With Various Resolutions, Using The Same Device appeared first on Distillery. -
How to Document API Requests using Django Rest Swagger
In Developing an application, we'll write our required API's. To Document these API's we use Django Rest Swagger. Django Rest Swagger is used to provide Documentation for all API's which are used in your application with brief description about each API individually. It is Open Source so you can contribute to the project. If your API's available to the users with description, so UI developers can understand and test your API's and use it accordingly. First we need to install the swagger. pip install django-rest-swagger Add "rest_framework_swagger" to Django settings INSTALLED_APPS INSTALLED_APPS = ( ... 'rest_framework_swagger', ) Include the rest_framework_swagger URLs to a path of your choice patterns = ('', ... url(r'^docs/$', schema_view, name="schema_view"), ) In your API Views from rest_framework.decorators import api_view, permission_classes, renderer_classes from rest_framework.permissions import AllowAny from rest_framework_swagger.renderers import OpenAPIRenderer, SwaggerUIRenderer @api_view() @permission_classes((AllowAny, )) @renderer_classes([OpenAPIRenderer, SwaggerUIRenderer]) def schema_view(request): generator = schemas.SchemaGenerator(title='Rest Swagger') return Response(generator.get_schema(request=request)) If you are not authorized, This document List all the API which doesnt reguire any permission to get authorize. If you want to use Rest Swagger in your application to authorize user, include below settings in your settings.py file. By this … -
Django and nginx file proxy - part two
You have our application up and running but there is a problem. You don't want the user to see that your media files are served from media url. How to fix that? This blog post will tell you one of the solutions. Let's go! How to hide urls from the … -
PyGrunn: creating abstraction between consumer and datastore - Marco Vellinga
(One of my summaries of a talk at the 2017 PyGrunn conference). Marco Vellinga started his talk with train-related analogies and photos, which I of course liked. They have a big monolythic application. Like a big train: move one part (a locomotive) and the rest also moves. In an application you don't want that: if you make a change in one part of the application, you don't want to have to change lots of other parts. Decoupled is better. With abstraction, for instance a user object with username, password and billing information, you can change the backend (splitting user and billing info, for instance) without needing to change anything in the frontend. They created an abstraction layer containing core logic validation error handling data contracts There isn't really support for such a layer in Django, so you have to build it yourself. This was a lot of work and took a couple of tries to get it right. They used Marshmallow for json serialization. For serializing queries (the equivalent of django's 'Q' objects) they build filterql. For (API) versioning they build their own function/class decorator to mark functions as "version 1" or "version 2". They're calling it versionary. It is … -
PyGrunn: django localization ('l10n') - Cees van Wieringen
(One of my summaries of a talk at the 2017 PyGrunn conference). What is L10N (=LocalizatioN)? You have multiple terms like that. Translation (t9n): just translating text. Localization: the adaption of a product or content to a specific language or culture. This includes localization. But also date/time formats. Currency. Units of measurement. Number formatting. i18n (internationalization) is preparing your product for localization. Using unicode. Django translation toolkit. Translation in django. Enable it in your settings.py by adding I18N = True. And use _() around your strings. Where does the underscore function come from? It is a gettext function: from django.utils.translation import gettext as _ There are multiple gettext variants (gettext_lazy, for instance), so he thinks it best to use the full function name instead of the customary underscore. Sometimes you have terms that can be translated in multiple ways. Django has a gettext function that allows adding a "domain". "Spring" can be a "season", but it can also be a "mechanical part". For translating models, there are multiple django apps that handle it and that store the various translations in the database. But there is none that tries to grab the translation from the existing gettext *.po translation files. So … -
PyGrunn: looking at molecules using python - Jonathan Barnoud
(One of my summaries of a talk at the 2017 PyGrunn conference). He researches at fat molecules. He applies simulation to molecules. F = m * a (+ some much more elaborate formulas). With an elaborate simulation, he was able to explain some of the properties of fat (using a "jupyter" notebook). His (python) workflow? First you need to prepare the simulation. He did have (of did build) a simulation engine. The preparation takes text files with the following info: Topology. Initial coordinates. Simulation parameters. Those text files are prepared and fed to the simulation engine. What comes out is a trajectory (a file with the position and direction and speed of every single molecure for all timesteps). The next step is analysis. A problem here is that various simulation engines export different formats.... Similar problem with the input, btw... Luckily we've got python. And for python there are a huge amount of libraries. Including "MDAnalysis" (http://www.mdanalysis.org/) , a library that can use these trajectory files. The output: python numpy arrays. Nice! This way you can use the entire python scientific stack (numpy, scipy, etc) with all its power. Numpy? Made for matrices. So you can work with your entire … -
PyGrunn: deep learning with tensorflow ("Trump tweet generator") - Ede Meijer
(One of my summaries of a talk at the 2017 PyGrunn conference). He originally used a java solution for 'machine learning', but that didn't work very comfortably. He then switch to tensorflow, written in python. Machine learning is learning from data without being explicitly programmed. You feed the computer lots of data and it learns from that. Some examples of the techniques used: linear regression, logistic regression, decision trees, artifical neural networks and much more. Artificial neural networks are what tensorflow is about. A normal neural network has "input layer", a "hidden layer" and "an output layer". The nodes in the three layers are connected. The neural net tries to learn the "weights" of the connections. Deep learning means you have neural networks with multiple hidden layers. Often it deals with features at different levels of abstractions. Images that have to be recognized can be cut in to several pieces of different sizes and fed to the net as those parts, but also as the full image. Training a model often works wit minimizing error by using the "gradual descent" method. Tensor flow? What are tensors? Well, a 0D tensor is a scalar, 1D a vector, 2D a matrix, etc. … -
PyGrunn: google machine learning APIs for python developers - keynote from Google Cloud
(One of my summaries of a talk at the 2017 PyGrunn conference). Lee Boonstra and Dmitriy Novakovskiy gave the keynote. Python at google. Python is widely used at google, it is one of its official languages. It is integral to many of the google projects, for instance youtube and 'app engine'. And lots of open source libraries. Every API has its own python client. Google for python developers. What can you do as a python programmer on google? Google cloud platform. It consists of many parts and services that you can use. You can embed machine learning services like tensorflow, speach API, the translation API, etc. Serverless data processing and analytics. Pub/Sub, bigquery (map/reduce without needing to run your own hadoop cluster), etc. Server stuff like kubernetes, container services. Machine learning. There have been quite some presentation on this already. Look at it like this: how do you teach things to your kids? You show them! "That is a car", "that is a bike". After a while they will start learning the words for the concepts. Machine learning is not the same as AI (artificial intelligence). AI is the process of building smarter computers. Machine learning is getting the computer … -
PyCon tutorials, day one
11:39: This morning’s tutorial was on the OpenAPI specification, née Swagger. I wasn’t satisfied with this one. Much of it was a series of, “Look at X. Now make the changes in your file that are like X,” exercises. At times it was almost pattern-matching in nature. I wish it had spent more time delving under the covers. However, I extracted some useful nuggets of information. In previous jobs, my teams have used Django Rest Framework for the API implementation and django-rest-swagger to generate live documentation. Time-consuming, “now you have two problems,” issues were always encountered. Django Rest Framework is a framework in and of itself, and so it’s a framework wrapping another framework. Add in django-rest-swagger and you almost have three frameworks, with multiple points of impedance mismatch to each other. (This is understandable. It’s amazing it all works as well as it does.) The process of keeping it all happy took time, and the end results were problematic. In at least two instances, my team chose to lower the API’s quality in order to keep using DRF. One pain point was nested parameters; they (particularly modifiable ones) were extraordinarily painful. So, back to the tutorial. Coffee Meets Bagel’s … -
Using Python and Google Docs to Build Books
When I started my latest fiction book, The Darkest Autumn, I wrote out the chapters as individual files. I did it in a text editor (Sublime) and saved the files to a git repo. The names of the files determined their order, chapters being named in this pattern: the-darkest-autumn $ tree . ├── 01_Beginnings.md ├── 02_Town_of_Ravenna.md ├── 03_Walls_of_Ravenna.md As the book developed I thought about moving it to Scrivener. If you don't know, Scrivener is an excellent tool for writing. It encourages you to break up your work into chapters and scenes. The downside is that Scrivener is complex (I want to write, not figure out software) and Scrivener isn't designed for simultaneous collaboration. The latter issue is a very serious problem, as I like to have others review and comment on my writing as I go. What I really wanted to do is combine the chapter breaking of Scrivener with the simplicity and collaboration of Google Docs. Preferably, I would put the book chapters into Google Docs as individual files and then send invites to my editor, wife, and my beta readers. By using Google Docs I could ensure anyone could access the work without having to create a … -
Using Python and Google Docs to Build Books
When I started my latest fiction book, The Darkest Autumn, I wrote out the chapters as individual files. I did it in a text editor (Sublime) and saved the files to a git repo. The names of the files determined their order, chapters being named in this pattern: the-darkest-autumn $ tree . ├── 01_Beginnings.md ├── 02_Town_of_Ravenna.md ├── 03_Walls_of_Ravenna.md As the book developed I thought about moving it to Scrivener. If you don't know, Scrivener is an excellent tool for writing. It encourages you to break up your work into chapters and scenes. The downside is that Scrivener is complex (I want to write, not figure out software) and Scrivener isn't designed for simultaneous collaboration. The latter issue is a very serious problem, as I like to have others review and comment on my writing as I go. What I really wanted to do is combine the chapter breaking of Scrivener with the simplicity and collaboration of Google Docs. Preferably, I would put the book chapters into Google Docs as individual files and then send invites to my editor, wife, and my beta readers. By using Google Docs I could ensure anyone could access the work without having to create a … -
Runtime Permissions in Android: The What, Why, and How
It’s great if you are dealing with an application from a famous and well-known developer whom you can trust. But imagine that you want to install a music player that requires, let’s say, information about your location. It looks very suspicious, doesn’t it? The post Runtime Permissions in Android: The What, Why, and How appeared first on Distillery. -
Kubernetes Health Checks in Django
Kubernetes Health Checks in Django -
Django and nginx file proxy - part one
In this blog post series, I will show you how to use Nginx for hiding download urls. Django will serve us as a backend. Let's go! In this series I will build simple web application - user upload a file via api and then she/he wants to download it. But …