qq_42650062
qq_42650062
采纳率0%
2019-04-01 18:08 阅读 627

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条回答 默认 最新

  • weixin_42849517 weixin_42849517 2019-04-01 18:14

    不要用中文名当路径啊

    运行命令是怎么样的

    点赞 1 评论 复制链接分享
  • hallen41 hallen41 2019-04-04 10:01

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

    点赞 1 评论 复制链接分享
  • yueguangMaNong 做我的code吧 2019-04-04 16:37

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

    点赞 1 评论 复制链接分享
  • qq_42650062 qq_42650062 2019-04-01 19:24

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

    点赞 评论 复制链接分享

相关推荐