Dodgedoge
Dodgedoge

Reputation: 13

my django looks like can`t recognize the templates

i am a noob learning python,when i learning the template of django,i met some mistakes;what i am using is pycharm2016.2.3 ,python3.5.2,django1.10.1

here is my dir list:

│  db.sqlite3
│  manage.py
├─djangotest
│  │  settings.py
│  │  urls.py
│  │  view.py
│  │  wsgi.py
│  │  __init__.py
│
└─templates
   hello.html

the url.py:

from django.conf.urls import url
from django.contrib import admin

urlpatterns = [
    url(r'^admin/', admin.site.urls),

]

the setting.py:

TEMPLATES = [
    {
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [os.path.join(BASE_DIR, 'templates')]
    ,
    'APP_DIRS': True,
    'OPTIONS': {
        'context_processors': [
            'django.template.context_processors.debug',
            'django.template.context_processors.request',
            'django.contrib.auth.context_processors.auth',
            'django.contrib.messages.context_processors.messages',
        ],
    },

the hello.html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>temtest</title>
</head>
<body>
<h1>{{ hello }}</h1>
</body>
</html>

the view.py:

#coding:utf-8
from django.http import HttpResponse
from django.shortcuts import render

def hello(request):
    context = {}
    context['hello'] = 'yes i am'
    return render(request,'hello.html',context)
def first_page(request):
    info = 'on yes'
    return HttpResponse(info)

when i run and type 127.0.0.1:8000 i can open it successfully, but when i type 127.0.0.1:8000/hello ,it show me this:enter image description here

it seems like that the templates can`t be recognized. can somebody do me a flavor? thank you!

Upvotes: 1

Views: 45

Answers (1)

Alex
Alex

Reputation: 6047

You're missing a url definition :

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^hello$/', djangotest.hello),
]

Upvotes: 1

Related Questions