Django构建博客,连接数据库失败

时间:2014-07-26 10:29:35

标签: python django macos django-models

我是一个python和Django学习者。我按照教程 (http://www.creativebloq.com/netmag/get-started-django-7132932)和我的mac 并遇到了一些问题。

xinliu-mac:netmag xinliu$ python manage.py syncdb
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Library/Python/2.7/site-packages/Django-1.7c1-py2.7.egg/django/core/management/__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "/Library/Python/2.7/site-packages/Django-1.7c1-py2.7.egg/django/core/management/__init__.py", line 354, in execute
    django.setup()
  File "/Library/Python/2.7/site-packages/Django-1.7c1-py2.7.egg/django/__init__.py", line 21, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Library/Python/2.7/site-packages/Django-1.7c1-py2.7.egg/django/apps/registry.py", line 106, in populate
    app_config.import_models(all_models)
  File "/Library/Python/2.7/site-packages/Django-1.7c1-py2.7.egg/django/apps/config.py", line 190, in import_models
    self.models_module = import_module(models_module_name)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/Users/xinliu/djcode/netmag/blog/models.py", line 16
    return u'&s % self.title
                           ^
SyntaxError: EOL while scanning string literal

我的settings.py数据库是:

 60 DATABASES = {
 61     'default': {
 62         'ENGINE': 'django.db.backends.sqlite3',
 63         'NAME': os.path.join(BASE_DIR, 'netmag.db'),
 64     }
 65 }

,路径是:

 12 import os
 13 BASE_DIR = os.path.dirname(os.path.abspath(__file__))

那有什么不对?

1 个答案:

答案 0 :(得分:0)

错误在:

  File "/Users/xinliu/djcode/netmag/blog/models.py", line 16
       return u'&s % self.title

有两个错误。

  1. 缺少一行:return '&s' % self.title
  2. 第二个是%而不是&所以它必须是:return '%s' % self.title