Django: Quick guide on how to develop web pages using this framework
At BBVAOpen4U, we have described how to start using JavaScript development frameworks such as AngularJS, EmberJS and BackboneJS. However, we have yet to mention other popular frameworks such as Django: the open-source development framework on Python which is particularly useful to quickly create web applications. This is a quick guide for beginners on how to install and start using the tool.
Before we start, we need to know that Django really is about, its main characteristic and how to make the most of it:
● This framework’s main goal is to enable hassle-free creation of web applications. It intends to be simple and quick so that “you can concentrate on writing your application without having to reinvent the wheel.” An almost perfect summary of Django would be: quick programming of web pages and applications. This is possible thanks to Python, a simple, direct and highly efficient language (the code volume necessary to program any digital project is extremely low).
● Based on the DRY philosophy (Don’t Repeat Yourself). A lot of web applications and digital projects share numberless code lines. Django is almost synonymous with code refactoring. It allows you to use programming between applications without having to repeat the same code lines in different projects.
● Django is a high-level web framework based on the Model-View-Controller paradigm. And this couldn’t be any different since Django is a development framework focused on simplicity, speed and code reuse. So, we have the data (the model), the user interface (the view) and the business logic (the controller).
● Embedded database. Django is supplied with SQLite, a database used by major companies such as Facebook and Bloomberg.
● ORM system for connecting to databases. ORM is the system the development framework uses to connect with and store data in the database. Querysets are essential for this process. They are lists of model data that can be read, sorted and filtered. This short guide explains how to choose, sort or filter model objects.
● API dedicated to developing digital projects. Django REST framework is a set of tools for developers to build browsable Web APIs which are compatible with reading ORM or non-ORM data and with authentication policies based on well-know packages such as OAuth1 and OAuth2.
How to start developing with Django
It is very easy to download the zipped file with the Django folder, and install it on any workstation (Windows, Mac OSX and Linux). To start developing with Django, follow these steps:
● Download the zipped file from Django’s website. The latest available version is 1.9.1. Version 1.10 is scheduled to be launched in August 2016. Once you have downloaded and unzipped the file, install Django on your machine using pip. Command:
pip install Django==1.9.1
● Alternatively, you can use Git, an open-source version control system free of charge. Installation takes place through this command interpreter but, naturally, first you need to install Git.
git clone https://github.com/django/django.git
● Django has some dependencies and requirements which you must also install to be able to use this framework:
– The first dependency is the programming language Python. It is recommended that you use Python 3, albeit Django is also compatible with version 2.7.
– The second dependency is the installation of an independent web server (Django has its own light development server but it cannot be used as a production server). This server must be based on the WSGI PEP 3333 specification. The specification allows you to choose from a wide range of servers for digital projects with Django.
– The third requirement is a compatible database. There are several options: PostgreSQL, MySQL, SQLite3 and Oracle.
Creating a project
To begin a digital project in Django, you need to:
● Create the directory for the new project. Run the command: django-admin.py startproject mysite. In technical terms, it is recommended that you place this directory outside the server’s root folder to prevent security issues. The command creates the directory mysite, a generic name:
– mysite/urls.py: urls statement for the new website.
– mysite/wsgi.py: Server specification file.
Configuring the database in Django
To configure the database you have chosen for the Django project (PostgreSQL, MySQL, SQLite3 or Oracle), you need to change the configuration options of file mysite/settings.py. You need to change the DATABASESdefault element and make it compatible with the selected database. As with most database configurations, the following is changed:
– name: Database name; it must always correspond to the whole path, including the file name. E.g. for a Windows machine: C:/home/user/mysite/sqlite3.db if the database for the Django development project is SQLite3.
Banco Bilbao Vizcaya Argentaria, S.A. owner of this portal uses cookies and/or similar technologies of its own and third parties for the purposes of personalization, analytics, behavioral advertising or advertising related to your preferences based on a profile prepared from your browsing habits (e.g. pages visited). If you wish to obtain more detailed information, consult our Cookies Policy.
Cookie settings panel
These are the advanced settings for first-party and third-party cookies. Here you can change the parameters that will affect your browsing experience on this website.
Technical Cookies (required)
These cookies are used to give you secure access to areas with personal information and to identify you when you log in.
Name
Owner
Duration
Description
gobp.lang
BBVA
1 month
Language preference
aceptarCookies
BBVA
1 year
Configuration Accepted Cookies
_abck
BBVA
1 year
Helps protect against malicious website attacks
bm_sz
BBVA
4 hours
Helps protect against malicious website attacks
ADRUM_BTs
Salesforce Marketing Cloud
Session
Required for monitoring of the service, inherent to SFMC
ADRUM_BT1
Salesforce Marketing Cloud
Session
Required for monitoring of the service, inherent to SFMC
ADRUM_BTa
Salesforce Marketing Cloud
Session
Required for monitoring of the service, inherent to SFMC
ADRUM_BT
Salesforce Marketing Cloud
Session
Required for monitoring of the service, inherent to SFMC
xt_0d95e
Salesforce Marketing Cloud
Session
Remember user preferences (if any)
__s9744cdb192d044faa1bf201d29fafd1e
Salesforce Marketing Cloud
Session
Remember user preferences (if any)
wpml_browser_redirect_test
WPML
Session
Text translation in the portal
wp-wpml_current_language
WPML
24 hours
Text translation in the portal
Analytics Cookies
They are used to track the activity or number of visits anonymously. Thanks to them we can constantly improve your browsing experience
Your browsing experience is constantly improving.
With your selection, we cannot offer you a continuously improved browsing experience.
Name
Owner
Duration
Description
AMCV_***
Adobe Analytics
Session
Unique Visitor IDs used in Cloud Marketing solutions
AMCVS_***
Adobe Analytics
2 years
Unique Visitor IDs used in Cloud Marketing solutions
demdex (safari)
Adobe Analytics
180 days
Create and store unique and persistent identifiers
sessionID
Adobe Analytics
Session
Launch's internal cookie used to identify the user
gpv_URL
Adobe Analytics
Session
Adobe Analytics plugin: getPreviousValue Capture the value of a certain variable in the following page view, in this case the prop1
gpv_level1
Adobe Analytics
Session
Cookie used to store the DataLayer levl1 of the previous page.
gpv_pageIntent
Adobe Analytics
Session
Cookie used to store the pageIntent of the previous page.
gpv_pageName
Adobe Analytics
Session
Cookie used to store the pagename of the previous page.
aocs
Adobe Analytics
Session
Cookie that stores the first values collected at the beginning of a process.
TTC
Adobe Analytics
Session
Cookie used to store the time between the App Page Visit event and the App Completed event.
TTCL
Adobe Analytics
Session
Cookie used to store the time between the LogIn event and App Completed.
s_cc
Adobe Analytics
Session
Determine if cookies are active
s_hc
Adobe Analytics
Session
Cookie used by Adobe for analytical purposes
s_ht
Adobe Analytics
Session
Cookie used by Adobe for analytical purposes
s_nr
Adobe Analytics
2 years
Determine the number of user visits
s_ppv
Adobe Analytics
Permanent
Adobe Analytics plugin: getPercentPageViewed Determine what percentage of the page a user views
s_sq
Adobe Analytics
Session
ClickMap/ActivityMap features
s_tp
Adobe Analytics
Session
Cookie used by Adobe for analytical purposes
s_visit
Adobe Analytics
2 years
Cookie used by Adobe to know when a session has been started.
Advertising Cookies
They allow the advertising shown to you to be customized and relevant to you. Thanks to these cookies, you will not see ads that you are not interested in.
The advertising is customized to you and your preferences.
Your choice means you will not see customized ads, only generic ones.
Name
Owner
Duration
Description
OT2
VersaTag
90 days
VersaTag Cookie used to store a user id and the number of user visits.
u2
VersaTag
90 days
VersaTag Cookie where the user ID is stored
TargetingInfo 2
MediaMind
1 year
Cookie that serves to assign a unique random number that generates MediaMind.
Customization Cookies
These cookies are related to general features such as the browser you use.
Your experience and content have been customized.
With your selection, we cannot offer you a continuously improved browsing experience.
Name
Owner
Duration
Description
mbox
Adobe Target
9 days
Cookie used by Adobe Target to test user experience customization.
Looks like you’re browsing from MexicoSpainArgentinaPeruColombiaBelgiumChileUSAFranceHong KongItalyPortugalUnited KingdomTurkeyUruguayVenezuelaAlemania, so let’s show you the custom content for your
location. Change
Select a country
In order to access the private area and corresponding sandbox, select the country of the APIs you want to use.