django刚入门,创建博客的时候出现这个错误,求解决

图片说明
图片说明

具体代码如下

html文件应该没错
views.py:
from django.shortcuts import render

Create your views here.

from django.template import loader,Context
from django.http import HttpResponse
from blog.models import BlogPost

def archive(request):
posts = BlogPost.objects.all(); #@UndefinedVariable
t = loader.get_template('archive.html')
c = Context({'posts': posts})
return HttpResponse(t.render(c))

models.py:
from django.db import models
from django.contrib import admin

Create your models here.

class BlogPost(models.Model):
title = models.CharField(max_length = 150)
content = models.TextField()
timestamp = models.DateTimeField()
class BlogPostAdmin(admin.ModelAdmin):
list_display = ('title', 'content', 'timestamp')

admin.site.register(BlogPost, BlogPostAdmin)

settings.py:
TEMPLATE_DEBUG = True

ALLOWED_HOSTS = []

Application definition

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

MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
)

ROOT_URLCONF = 'wangxiran.urls'

WSGI_APPLICATION = 'wangxiran.wsgi.application'

Database

https://docs.djangoproject.com/en/dev/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME':'wangxiran',
'USER':'root',
'PASSWORD':'Aa123456',
'HOST':'127.0.0.1',
'POST':'3306',
}
}

Internationalization

https://docs.djangoproject.com/en/dev/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'Asia/Shanghai'

USE_I18N = True

USE_L10N = True

USE_TZ = True

Static files (CSS, JavaScript, Images)

https://docs.djangoproject.com/en/dev/howto/static-files/

STATIC_URL = '/static/'

urls.py:
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()

from blog.views import archive
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'wangxiran.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),

url(r'^admin/', include(admin.site.urls)),
url(r'^blog/', archive),

)

照着网上教材做的 但是就是出不来啊 求大佬们帮帮

4个回答

不要用中文名当路径啊

运行命令是怎么样的

在浏览器访问,127.0.0.1:8000/admin,后面的是你的管理员url,也可以是博客的url,访问路径不对而已

图片里面其实已经提示了,你只有两个url可用,但是很明显,你访问的url(图片中是空的)不在url列表里面,所以找不到路径

那个是谷歌浏览器翻译出来的

weixin_42849517
weixin_42849517 那么 ^博客/ ^管理员/这个是怎么出现的
一年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问