gpt4 book ai didi

使用sqlite3进行Django设置?

转载 作者:行者123 更新时间:2023-12-04 05:38:10 26 4
gpt4 key购买 nike

我正在尝试按照django网站上的演练进行操作,我下载了sqlite并将其保存在C:\Windows\System32文件夹中。当我编辑settings.py文件时,应在Name字段中输入什么?我必须建立一个数据库吗? django的文献说,API应该为sqlite处理。当我运行python manage.py syncdb时,我只会遇到很多错误。我究竟做错了什么?

    Jason & Casey@SUPERBEAST ~/Desktop/mysite
$ python manage.py syncdb
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "c:\Python27\lib\site-packages\django\core\management\__init__.py", line
443, in execute_from_command_line
utility.execute()
File "c:\Python27\lib\site-packages\django\core\management\__init__.py", line
382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "c:\Python27\lib\site-packages\django\core\management\__init__.py", line
252, in fetch_command
app_name = get_commands()[subcommand]
File "c:\Python27\lib\site-packages\django\core\management\__init__.py", line
101, in get_commands
apps = settings.INSTALLED_APPS
File "c:\Python27\lib\site-packages\django\utils\functional.py", line 184, in
inner
self._setup()
File "c:\Python27\lib\site-packages\django\conf\__init__.py", line 42, in _set
up
self._wrapped = Settings(settings_module)
File "c:\Python27\lib\site-packages\django\conf\__init__.py", line 93, in __in
it__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "c:\Python27\lib\site-packages\django\utils\importlib.py", line 35, in im
port_module
__import__(name)
File "c:\Users\Jason & Casey\Desktop\mysite\mysite\settings.py", line 21
}
^
SyntaxError: invalid syntax

最佳答案

我还没有在Windows下尝试过django,但是python 2.7肯定带有sqlite开箱即用的功能。

如何设置数据库?

在文件顶部:

import os

然后:
PROJECT_DIR = os.path.abspath(os.path.dirname(__file__))
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(PROJECT_DIR, 'yourdatabasename.db'),
}
}

最后,syncdb应该可以解决问题。

如果它不起作用,介意粘贴回溯吗?

关于使用sqlite3进行Django设置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13301419/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com