• Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial News Comments FAQ Related Articles

How To Create Web Applications using Django-Part 2

{{postValue.id}}

Creating Basic Web Applications using Django Framework

Django is a free source web framework written in Python Language and creates web application faster. It allows your applications and sites to up and run quicker without worry about the common structural code to tie it together.

To install and create a web application to develop an administrative user login using Django, visit
www.linuxhelp.com/how-to-install-and-configure-django-in-centosdebian/
www.linuxhelp.com/create-web-application-using-django/
In this tutorial we will learn how to create a own webpage using Django.

To view Default website running through Django

Execute the below command to run the server in an activated virtual environment and check the currently running website inside Django.

(myproject)root@linuxhelp:~/django/sampleproject# python manage.py runserver 0.0.0.0:8000
Performing system checks...
System check identified no issues (0 silenced).
April 29, 2016 - 13:00:12
Django version 1.9.5, using settings ' sampleproject.settings' 
Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.


Now open your web browser and type your IP address along with the port no.(8000).
web browser

The default webpage opens as shown below.
default web page

Instead of this default site we are going to create our own simple and basic website by using Django.
Go to the directory ' myapp' created for our web application inside the project directory. And add the following entry in views.py file.

Entry:
From django.shortcuts import render, render_to_response
#Create your vies here.
Def index(request):
Return render_to_response(‘ index.html’ )


The file views.py will be in charge of returning index file for your site (index.html), that we are going to create.

To create index page for our site

Now create a directory called template under ' myapp' to store the index pages of our site.


(myproject)root@linuxhelp:~/django/sampleproject/myapp# mkdir templates
(myproject)root@linuxhelp:~/django/sampleproject/myapp# cd templates/
(myproject)root@linuxhelp:~/django/sampleproject/myapp/templates# vim index.html


Write the source code for your website in index.html file. This file will be the index page for our basic website.

Entry:
< !DOCTYPE html> 
< html> 
< body> 
< h1> Welcome to linuxhelp< /h1> 
< p> This is basic website.< /p> 
< /body> 
< /html> 


Locate urls.py file under the Django project directory to set up a mapping between urls in our application and the corresponding views that return the data.


(myproject)root@linuxhelp:~/django/sampleproject# ls
db.sqlite3  manage.py  myapp  sampleproject
(myproject)root@linuxhelp:~/django/sampleproject# cd sampleproject/
(myproject)root@linuxhelp:~/django/sampleproject/sampleproject# ls
__init__.py   settings.py   urls.py   wsgi.py
__init__.pyc  settings.pyc  urls.pyc  wsgi.pyc
(myproject)root@linuxhelp:~/django/sampleproject/sampleproject# vim urls.py


Now create the entry as follows.

Entry:
from django.conf.urls import include, url
from django.contrib import admin
from myapp import views
urlpatterns = [
    url(r' ^admin/' , include(admin.site.urls)),
    url(r' ^$' , views.index),
]


Now start the Django server by running the following command.


(myproject)root@linuxhelp:~/django/sampleproject# python manage.py runserver 0.0.0.0:8000
Performing system checks...
System check identified no issues (0 silenced).
April 29, 2016 - 13:33:00
Django version 1.9.5, using settings ' sampleproject.settings' 
Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.


Open the browser and type the IP along with the port(8000) to view the website we have created.
welcome page

Tags:
cameron
Author: 

Comments ( 0 )

No comments available

Add a comment
{{postCtrl.cmtErrMsg}}

Frequently asked questions ( 5 )

Q

Why I got the error when accessing the developing page?

A

You probably forgot to start the development server. Go to your Django project directory and use the sh RUN command (which is mentioned in the Django installation mail) to start the development server.

Q

Does Django support NoSQL databases?

A

NoSQL databases are not officially supported by Django itself. There are, however, a number of side project and forks which allow NoSQL functionality in Django

Q

Can I use Django with a pre-existing database?

A

yes, You can create a pre-existing database in Django.

Q

What Python version should I use with Django?

A

These are the versions you can use
Django version Python versions
1.11 2.7, 3.4, 3.5, 3.6
2.0 3.4, 3.5, 3.6, 3.7
2.1, 2.2 3.5, 3.6, 3.7

Q

How to create an index page for our site in Django?

A

By this method, you can create an index page
~/django/sampleproject/myapp# mkdir templates
/django/sampleproject/myapp/templates# vim index.html

Back To Top!
Rank
User
Points

Top Contributers

userNamenaveelansari
135850

Top Contributers

userNameayanbhatti
92510

Top Contributers

userNamehamzaahmed
32150

Top Contributers

1
userNamelinuxhelp
31040

Top Contributers

userNamemuhammadali
24500
Can you help David Lopez Guillen ?
Ayuda urgente instale SSL para servidor Opensuse y ahora no funciona tengo servicio web

hola segui este tutorial para tener un certificado ssl y ahora no se ve mi app en la red, espero alguien pueda ayudarme, tengo M9oodle en3.5 en un servidor open suse y ahora no funciona por favor ayuda.

https://www.linuxhelp.com/how-to-create-ssl-certificate-in-opensuse

Networking
  • Routing
  • trunk
  • Netmask
  • Packet Capture
  • domain
  • HTTP Proxy
Server Setup
  • NFS
  • KVM
  • Memory
  • Sendmail
  • WebDAV
  • LXC
Shell Commands
  • Cloud commander
  • Command line archive tools
  • last command
  • Shell
  • terminal
  • Throttle
Desktop Application
  • Linux app
  • Pithos
  • Retrospect
  • Scribe
  • TortoiseHg
  • 4Images
Monitoring Tool
  • Monit
  • Apache Server Monitoring
  • EtherApe 
  • Arpwatch Tool
  • Auditd
  • Barman
Web Application
  • Nutch
  • Amazon VPC
  • FarmWarDeployer
  • Rukovoditel
  • Mirror site
  • Chef
Contact Us | Terms of Use| Privacy Policy| Disclaimer
© 2025 LinuxHelp.com All rights reserved. Linux™ is the registered trademark of Linus Torvalds. This site is not affiliated with linus torvalds in any way.