SyntaxError:无效语法Django NAME settings.py

时间:2013-11-16 03:29:59

标签: python django

我是Django和SQL的新手,所以我正在通过民意调查教程。问题是当我在settings.py中设置NAME然后运行python manage.py syncdb时,我不断收到sytax错误。

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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': /home/silight/Desktop/Python/django/first (BASE_DIR, 'db.sqlite3'),
    }
}

这是我终端的相关输出。

  File "/home/silight/Desktop/Python/django/poll/poll/settings.py", line 61
    'NAME': /home/silight/Desktop/Python/django/first (BASE_DIR, 'db.sqlite3'),
            ^
SyntaxError: invalid syntax

这是tutorial的解释。

NAME – The name of your database. If you’re using SQLite, the database will be a file on         
your computer; in that case, NAME should be the full absolute path, including filename, 
of that file. If the file doesn’t exist, it will automatically be created when you 
synchronize the database for the first time (see below).

When specifying the path, always use forward slashes, even on Windows (e.g.     
C:/homes/user/mysite/sqlite3.db).

这可能是愚蠢的事,但如果你能指出我搞砸了什么,我将非常感激。

谢谢你们。

2 个答案:

答案 0 :(得分:1)

你忘记了引号:

'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': "/home/silight/Desktop/Python/django/first/db.sqlite3",
    }
}

就这么简单,希望这有帮助!

答案 1 :(得分:0)

试试这个:

'NAME': '/home/silight/Desktop/Python/django/first/db.sqlite3',

然而,在开始学习/使用Django之前,你应该真正学习Python编程的基础知识。

相关问题