I'm in the settings.py module, and I'm supposed to add the directory to the sqlite database. How do I know where the database is and what the full directory is?
我在settings.py模块中,我应该将目录添加到sqlite数据库。我如何知道数据库的位置以及完整目录的位置?
I'm using Windows 7.
我正在使用Windows 7。
2 个解决方案
#1
3
The absolute path of the database directory is what you need. For e.g. if your database is named my.db
and lives in C:\users\you\
then:
数据库目录的绝对路径是您所需要的。对于例如如果您的数据库名为my.db并且位于C:\ users \ you \:
DATABASE_ENGINE = 'sqlite3'
DATABASE_NAME = 'C:/users/you/my.db'
Update
更新
AFAIK you do not have to create the database yourself. The database will be created when you run syncdb
. The database can live in any directory you wish. If you want the database to be in you Django project directory just change the path accordingly.
AFAIK您不必自己创建数据库。运行syncdb时将创建数据库。数据库可以存在于您希望的任何目录中。如果你想让数据库在你的Django项目目录中,只需相应地改变路径。
For e.g. let us say your Django project lives in C:\users\you\myproject\
. You would then change your settings thus:
对于例如让我们说你的Django项目位于C:\ users \ you \ myproject \。然后,您将更改您的设置:
DATABASE_ENGINE = 'sqlite3'
DATABASE_NAME = 'C:/users/you/myproject/my.db'
#2
1
if you don't provide full path, it will use the current directory of settings.py, and if you wish to specify static path you can specify it like: c:/projects/project1/my_proj.db
如果你不提供完整路径,它将使用settings.py的当前目录,如果你想指定静态路径,你可以指定它:c:/projects/project1/my_proj.db
or in case you want to make it dynamic then you can use os.path module
或者如果你想让它变得动态,你可以使用os.path模块
so os.path.dirname(file) will give you the path of settings.py and accordingly you can alter the path for your database like os.path.join(os.path.dirname(file),'my_proj.db')
因此os.path.dirname(file)将为您提供settings.py的路径,因此您可以更改数据库的路径,如os.path.join(os.path.dirname(file),'my_proj.db')
#1
3
The absolute path of the database directory is what you need. For e.g. if your database is named my.db
and lives in C:\users\you\
then:
数据库目录的绝对路径是您所需要的。对于例如如果您的数据库名为my.db并且位于C:\ users \ you \:
DATABASE_ENGINE = 'sqlite3'
DATABASE_NAME = 'C:/users/you/my.db'
Update
更新
AFAIK you do not have to create the database yourself. The database will be created when you run syncdb
. The database can live in any directory you wish. If you want the database to be in you Django project directory just change the path accordingly.
AFAIK您不必自己创建数据库。运行syncdb时将创建数据库。数据库可以存在于您希望的任何目录中。如果你想让数据库在你的Django项目目录中,只需相应地改变路径。
For e.g. let us say your Django project lives in C:\users\you\myproject\
. You would then change your settings thus:
对于例如让我们说你的Django项目位于C:\ users \ you \ myproject \。然后,您将更改您的设置:
DATABASE_ENGINE = 'sqlite3'
DATABASE_NAME = 'C:/users/you/myproject/my.db'
#2
1
if you don't provide full path, it will use the current directory of settings.py, and if you wish to specify static path you can specify it like: c:/projects/project1/my_proj.db
如果你不提供完整路径,它将使用settings.py的当前目录,如果你想指定静态路径,你可以指定它:c:/projects/project1/my_proj.db
or in case you want to make it dynamic then you can use os.path module
或者如果你想让它变得动态,你可以使用os.path模块
so os.path.dirname(file) will give you the path of settings.py and accordingly you can alter the path for your database like os.path.join(os.path.dirname(file),'my_proj.db')
因此os.path.dirname(file)将为您提供settings.py的路径,因此您可以更改数据库的路径,如os.path.join(os.path.dirname(file),'my_proj.db')