In Django, views have to be created in the app views.py file.
See the following view −
from django.shortcuts import render
from django.http import HttpResponse
def hello(request):
return render(request, "hello.html", {})
A template: myapp/templates/hello.html
myapp\templates\hello.html
add url C:\myprojectdjango\myprojectdjango\urls.py
from django.conf.urls import patterns, include, url
from django.contrib import admin
from django.contrib import admin
admin.autodiscover()
urlpatterns = [
url(r'^admin/', admin.site.urls),
]
urlpatterns = patterns('myapp.views',
url(r'^hello/', 'hello', name = 'hello'),)
Run
python manage.py runserver
http://127.0.0.1:8000/hello/
