0
我是Django的新手,嘗試創建一個簡單的博客,但語法錯誤一直出現在Context行中的views.py文件中。我使用Django 1.6,語法似乎與此版本兼容。 下面是views.py簡單的方法,在這裏我得到的錯誤:django上下文語法錯誤
def archive(request):
posts = blogPost.objects.all()
t = loader.get_template("archive.html")
c = Context({'posts': })
return HttpResponse(t.render(c))
這裏的回溯:
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/blog
Django Version: 1.6
Python Version: 2.7.6
Installed Applications:
('django.contrib.auth',
'django.contrib.admin',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admindocs',
'blog')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')
Traceback:
File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in get_response
90. response = middleware_method(request)
File "C:\Python27\lib\site-packages\django\middleware\common.py" in process_request
71. if (not urlresolvers.is_valid_path(request.path_info, urlconf) and
File "C:\Python27\lib\site-packages\django\core\urlresolvers.py" in is_valid_path
573. resolve(path, urlconf)
File "C:\Python27\lib\site-packages\django\core\urlresolvers.py" in resolve
453. return get_resolver(urlconf).resolve(path)
File "C:\Python27\lib\site-packages\django\core\urlresolvers.py" in resolve
318. for pattern in self.url_patterns:
File "C:\Python27\lib\site-packages\django\core\urlresolvers.py" in url_patterns
346. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\Python27\lib\site-packages\django\core\urlresolvers.py" in urlconf_module
341. self._urlconf_module = import_module(self.urlconf_name)
File "C:\Python27\lib\site-packages\django\utils\importlib.py" in import_module
40. __import__(name)
File "C:\Python27\Lib\site-packages\django\bin\myblog\myblog\urls.py" in <module>
12. url(r'^blog/', include('blog.urls')),
File "C:\Python27\lib\site-packages\django\conf\urls\__init__.py" in include
26. urlconf_module = import_module(urlconf_module)
File "C:\Python27\lib\site-packages\django\utils\importlib.py" in import_module
40. __import__(name)
File "C:\Python27\Lib\site-packages\django\bin\myblog\blog\urls.py" in <module>
2. from blog.views import archive
Exception Type: SyntaxError at /blog
Exception Value: invalid syntax (views.py, line 14)
Tha NKS!有效。 Python是簡單的語言,使愚蠢的錯誤:) – OrangeJuice