Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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.

like image 908
Pompeyo Avatar asked Oct 29 '13 20:10

Pompeyo


People also ask

How do I import an existing Django project to PyCharm?

Open myproject as your project and then go to PyCharm -> Preferences... -> Django, Enable Django Support and then choose your Django project root, settings file and manage script. Save this answer.


1 Answers

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.

Checkout your paths inside your Django app. 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

Hope this helps!

like image 117
Paulo Bu Avatar answered Sep 25 '22 22:09

Paulo Bu