简体   繁体   English

如何将Django项目添加/导入virtualenv?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM