Tutorial 1: how to set the template and get the message hai welcome


Step:1(created the project and run it)
-----
$django-admin startproject dml
$cd dml
dml$ python manage.py runserver
Performing system checks...

System check identified no issues (0 silenced).
September 18, 2015 - 06:18:57
Django version 1.8.3, using settings 'dml.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.



Step:2(create a app)
-------
dml$ python manage.py startapp dmlapp


Step:3(create templates,index.html)(update setting.py,url.py,view.py)
-------
1. first create a template folder in dmlapp folder
2. in the template folder create index.html page

ie.

<html>
<body>hai welcome
</body></html>


Step:4(update setting.py,url.py,view.py)
------



dmlapp/view.py
-------


from django.shortcuts import render

# Create your views here.

def index(request):
    return render(request,'index.html')



url.py
----
from django.conf.urls import include, url
from django.contrib import admin
from dmlapp.views import index
urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
    url(r'^$','dmlapp.views.index', name='index'),

]




setting.py
---------



INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'dmlapp',
)




$python manage.py runserver






output:












No comments:

Post a Comment