Django使用sqlite3进行安装? [英] Django setup with sqlite3?
问题描述
C:\Windows\System32
文件夹中。当我编辑 settings.py
文件我为 Name
字段设置什么?我必须设置数据库吗? django文学说,API应该照顾sqlite。当我运行 python manage.py syncdb
我只是得到一堆错误。我做错了什么? Jason& Casey @ SUPERBEAST〜/ Desktop / mysite
$ python manage.py syncdb
追溯(最近的最后一次调用):
文件manage.py,第10行,< module>
execute_from_command_line(sys.argv)
文件c:\Python27\lib\site- packages\django\core\management\__init __。py,行
443,在execute_from_command_line
utility.execute()
文件c:\Python27\lib\site- packages\django\core\management\___it__。py,行
382,执行
self.fetch_command(子命令).run_from_argv(self.argv)
文件c:\Python27\lib\site-packages\django\core\\ \\ management\__init __。py,行
252,fetch_command
app_name = get_commands()[subcommand]
文件c:\Python27\lib\site- packages\\ \\ django \core\management\__init __。py,行
101,在get_commands
apps = settings.INSTALLED_APPS
文件c:\Python27\lib\site -packages\django\utils\functional.py,第184行,
inner
self._setup()
文件c:\Python27\\
self._wrapped =设置(settings_module)
文件c:\\ _Python27\lib\site-packages\django\conf\__init __。py,第93行,__in
it__
mod = importlib.import_module(self.SETTINGS_MODULE)
文件c:\Python27\lib\site-packages\django\utils\importlib.py,第35行,im
port_module
__import __(name)
文件c:\Users\Jason& Casey \Desktop\mysite\mysite\settings.py,第21行
}
^
语法错误:无效语法
我没有在windows下尝试过django,但是python 2.7肯定会带有sqlite开箱即用。
如何设置数据库?
在文件的顶部:
import os
then:
PROJECT_DIR = os.path.abspath(os.path.dirname(__ file__))
DATABASES = {
' ':{
'ENGINE':'django.db.backends.sqlite3',
'NAME':os.path.join(PROJECT_DIR,'yourdatabasename.db'),
}
}
最后一个syncdb应该做的伎俩。
如果不行,请记住粘贴追溯?
I am trying to follow the walkthrough on the django website and I downloaded sqlite and saved it in C:\Windows\System32
folder. When I edit the settings.py
file what do I put for the Name
field? Do I have to set up a database? The django literature say's that the API should take care of that for sqlite. When I run python manage.py syncdb
I just get a bunch of errors. What am I doing wrong?
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
I haven't tried django under windows but python 2.7 surely comes with sqlite out of the box.
How to setup the database?
on the top of the file:
import os
then:
PROJECT_DIR = os.path.abspath(os.path.dirname(__file__))
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(PROJECT_DIR, 'yourdatabasename.db'),
}
}
and finally a syncdb should do the trick.
If it doesn't work, mind to paste the traceback?
这篇关于Django使用sqlite3进行安装?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!