[英]How to add/import a Django project into a virtualenv?
I just starting to use virtualenv
and I want to import an old Django project into a new virtualenv
. 我刚刚开始使用
virtualenv
,我想将一个旧的Django项目导入到一个新的virtualenv
。 What is the best way to do this? 做这个的最好方式是什么?
I tried to just copy my old Django project inside the new virtualenv
, but Django is compiling with the old Path project and not with the one inside of the virtualenv
. 我试图将我的旧Django项目复制到新的
virtualenv
,但是Django使用旧的Path项目而不是virtualenv
内部的项目进行编译。
It should work immediately. 它应该立即工作。 Just copy/paste the Django app folder into the
virtualenv
environment and when you issue python manage.py runserver
on that folder, it should use virtualenv
's own python
binary with it's site-packages
path. 只需将Django应用文件夹复制/粘贴到
virtualenv
环境中,然后在该文件夹上发布python manage.py runserver
时,它应使用virtualenv
自己的python
二进制文件及其site-packages
路径。
Checkout your paths inside your Django app. 在Django应用中检出路径。 Don't hardwire them, you should do something like this:
不要硬连线 ,您应该执行以下操作:
import os
settings_dir = os.path.dirname(__file__)
PROJECT_ROOT = os.path.abspath(os.path.dirname(settings_dir))
and then concatenate PROJECT_ROOT
with everything you want to declare as path inside your settings.py
然后将
PROJECT_ROOT
与您要声明为settings.py
路径的所有内容连接起来
Hope this helps! 希望这可以帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.