Project

General

Profile

Feature #878

Updated by Daniel Curtis about 8 years ago

This is a condensed version of the Django tutorial found "here":https://docs.djangoproject.com/en/1.10/intro/tutorial01/ 

 h2. Setup The Environment 

 * Setup a python virtual environment to develop in 
 #* For Arch Linux use issue #876 
 #* For FreeBSD use issue #874 

 h2. Install Django 

 * Switch to the pydev user and activate the virtualenv: 
 <pre> 
 su - pydev 
 source ~/venv/new_app/bin/activate 
 </pre> 

 * And install Django: 
 <pre> 
 pip install Django 
 </pre> 

 h2. New Django App 

 * Create a new Django project and run the initial database migration: 
 <pre> 
 django-admin startproject www_example_com 
 cd www_example_com 
 ./manage.py migrate 
 </pre> 

 * Edit the project settings.py file: 
 <pre> 
 vi www_example_com/settings.py 
 </pre> 
 #* And add the host IP address of the local development machine: 
 <pre> 
 ALLOWED_HOSTS = ['192.168.1.90'] 
 </pre> 

 * Test the new app by running the development test web server: 
 <pre> 
 ./manage.py runserver 0.0.0.0:8000 
 </pre> 
 *NOTE*: Press @CTRL+C@ to stop the test web server 

 * Now create a new simple poll web application: 
 <pre> 
 ./manage.py startapp polls 
 </pre> 

 h3. Create View 

 * Create the initial view: 
 <pre> 
 vi polls/views.py 
 </pre> 
 #* And add the following: 
 <pre> 
 from django.shortcuts import render 
 from django.http import HttpResponse 

 def index(request): 
     return HttpResponse("Hello, world. You're at the polls index.") 
 </pre> 

 * Now map the view to a URL by creating: 
 <pre> 
 vi polls/urls.py 
 </pre> 
 #* And add the following: 
 <pre> 
 from django.conf.urls import url 

 from . import views 

 urlpatterns = [ 
     url(r'^$', views.index, name='index'), 
 ] 
 </pre> 

 * Next, point the root URLconf at the polls.urls module: 
 <pre> 
 vi mysite/urls.py 
 </pre> 
 #* And add the URL handler the @polls/@ part of the web application: 
 <pre> 
 from django.conf.urls import include, url 
 from django.contrib import admin 

 urlpatterns = [ 
     url(r'^polls/', include('polls.urls')), 
     url(r'^admin/', admin.site.urls), 
 ] 
 </pre> 

  

 h2. Resources 

 * https://docs.djangoproject.com/en/1.10/intro/tutorial01/

Back