我正在学习一个教程,以便学习Django,所以我真的很新。
我创建了一个名为etat_civil
的项目,并创建了一个名为blog
的应用程序。
我得到了这样的东西:
我的blog views.py
文件如下:
#-*- coding : utf-8 -*-
from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.
def home (request) :
text = u"""<h1>Bienvenue sur mon blog ! </h1>
<p>Les crêpes bretonnes ça tue des mouettes en plein vol ! </p>"""
return HttpResponse(text)
和我的etat_civil urls.py
文件如下:
#-*- coding : utf-8 -*-
from django.conf.urls import url
from django.contrib import admin
from blog import views
urlpatterns = [
url(r'^accueil$', views.home),
]
然后,在终端我执行了命令行:python manage.py run server
但是我收到了这个错误,我不知道这个错误在哪里:
macbook-pro-de-valentin:etat_civil valentinjungbluth$ python manage.py runserver
Performing system checks...
Unhandled exception in thread started by <function wrapper at 0x1109e1050>
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 121, in inner_run
self.check(display_num_errors=True)
File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 374, in check
include_deployment_checks=include_deployment_checks,
File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 361, in _run_checks
return checks.run_checks(**kwargs)
File "/usr/local/lib/python2.7/site-packages/django/core/checks/registry.py", line 81, in run_checks
new_errors = check(app_configs=app_configs)
File "/usr/local/lib/python2.7/site-packages/django/core/checks/urls.py", line 14, in check_url_config
return check_resolver(resolver)
File "/usr/local/lib/python2.7/site-packages/django/core/checks/urls.py", line 24, in check_resolver
for pattern in resolver.url_patterns:
File "/usr/local/lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/usr/local/lib/python2.7/site-packages/django/urls/resolvers.py", line 313, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/local/lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/usr/local/lib/python2.7/site-packages/django/urls/resolvers.py", line 306, in urlconf_module
return import_module(self.urlconf_name)
File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/valentinjungbluth/etat_civil/etat_civil/urls.py", line 22, in <module>
from blog import views
File "/Users/valentinjungbluth/etat_civil/blog/views.py", line 9
SyntaxError: Non-ASCII character '\xc3' in file /Users/valentinjungbluth/etat_civil/blog/views.py on line 10, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
非常感谢你能帮到我;)
答案 0 :(得分:2)
源代码编码定义中有一个额外的空间
改变这个:
#-*- coding : utf-8 -*-
对此:
#-*- coding: utf-8 -*-