Skip to main content

Posts

Showing posts from August, 2016

Django cheatsheet @djangoproject

Creating a Django project django-admin startproject <project_name> Create an app in a project python manage.py startapp <app_name> Run the project on a server python manage.py runserver Apply migrations on your app python manage.py migrate Import modules in your app In <project_name>/<app_name>/views.py : By default, the following views.py will be in your app folder: from django.shortcuts import render # Create your views here. Add the http module in views.py as shown below: from django.shortcuts import render from django.http import HttpResponse # Create your views here. def index(request): return HttpResponse('<h1>Hello Explorers!</h1>') Map the view to a url The default urls.py file in the <project_name> folder is as follows. from django.conf.urls import url from django.contrib import admin urlpatterns = [     url(r'^admin/', admin.site.urls), ] Ad