如何在开发环境中模拟 Django 项目的路径,使其与生产环境相同?
我需要设置 Django 开发环境。
我做了一个 git clone 并从本地计算机上的生产环境中提取了所有 django 项目文件(a href="http://vagrantup.com/" rel="nofollow">Vagrant 启用虚拟机)。
问题是我的本地计算机的项目路径与我的生产路径不同(并且我无法更改它),因此在本地计算机上查找 INSTALLED_APPS 下所述的模块时遇到问题。
例如,在生产中,我的项目位于 /myproject
文件夹中,而在我的本地计算机上,位于 /vagrant/web/myproject
下。
在生产中,我像这样访问我的应用程序模块:
INSTALLED_APPS = ( 'myproject.myapp')
也在 Django 应用程序中,我像这样访问各种应用程序模块:
from myproject.myapp.models import *
我需要做什么来模拟我的开发盒上模块的生产路径,这样我就不会必须更改本地计算机上模块的路径吗?
I need to setup a Django dev environment.
I did a git clone
and pulled all the django project files from production on my local machine (a Vagrant enabled VM).
The problem is that my local machine has a different path to the project than my production ( and I can't change that) so it's having problems finding modules stated under INSTALLED_APPS on my local machine.
For example on the production my project is on the /myproject
folder while on my local machine is under /vagrant/web/myproject
.
On the production I'm accessing my app modules like this:
INSTALLED_APPS = ( 'myproject.myapp')
Also within the Django apps I'm accessing various app modules like this:
from myproject.myapp.models import *
What do I need to do to emulate production paths to my modules on my dev box so I don't have to change the paths to the modules on my local machine?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
只要 settings.py 中没有硬编码路径,应用程序目录的路径就不重要,您使用的是什么 Web 服务器?
The path to your application directory should not matter there as long as you dont have hard-coded paths in settings.py, what web server are you using?
在你的settings.py中:
prj_root
将是你的根项目文件夹的路径In your settings.py:
And
prj_root
will be path to your root project folder如果您正在进行项目相对导入,您所需要做的就是确保项目正上方的路径位于
PYTHONPATH
上。您只需在命令行中发出以下命令:
如果您使用的是 virtualenv,则可以将该行添加到环境的 bin/activate 文件中。
If you're doing project-relative imports, all you need to do is ensure that the path directly above your project is on the
PYTHONPATH
.You need only issue the following at the command line:
If you're using virtualenv, you can add that line to your environment's bin/activate file.