5

I am a new to Django and have 0 experience with this framework.

I cloned a project from git it came with requirements.txt file, but I am not sure how to run it. Do I need to create virtual environment first and clone the project into the directory of the virtual environment, and then install the requirements?

Do I need to clone the project first into some folder and then create the virtual environment inside this folder and then install the requirements?

Do I need to use any special IDE to run the project? I tried opening the project in PyCharm, without creating a virtual environment first, and it asked me if I want to install the requirements.

I would be glad if someone could explain what is the correct way to run an already existing project.

0

2 Answers 2

7

Let's come to your doubts one by one :

  • Cloning a repo has nothing to do with Django. You are just making a copy of the code on your disk. Now the copy can be kept anywhere you like(say in ~/Desktop). Also, the directory of a virtual envt. just contains the code of modules you might directly import(like Django), and has nothing to do with the code of the django project. So cloning can be done before or after activating the virtual envt.
  • You need not create a virtual envt., but you should. A virtual envt. just ensures that you can have different versions of the same module for your different projects. It keeps things organised. So, for example you can create two different virtual envt.'s one with Django=2.0 and another with Django=1.9, to test your website for the two different Django versions.
  • requirements.txt contains all the modules you will be needing to run the django application. So you first create a virtual envt, activate it and then in the virtual envt., install all the modules you will need. Generally do pip install -r requirements.txt
  • Now all the required modules are installed, To run the website on a local server( which Django will create for you ), do python manage.py runserver and open in the browser.
  • No, you don't need an IDE to run the django project. Editing the code on any text editor and running the server from terminal works just fine.

P.S: If you are completely new to python, I would recommend using the conda python distribution. You can create new virtual envt. using conda create as well.

4
  • Regarding your third point, should the virtual environment be created in the project's directory?
    – Keselme
    Aug 16, 2018 at 7:48
  • You create a virtual environment from terminal. You can run multiple projects from the same virtual envt.. So no, you need not necessarily create the virtual envt. from the project directory. Aug 16, 2018 at 8:15
  • Do I need to copy the requirements file into the the virtual environment folder?
    – Keselme
    Aug 16, 2018 at 8:33
  • No, no. You just do pip install -r requirements,txt and it will install the required modules in your virtual envt folder. You need not move the file. Aug 16, 2018 at 10:09
2

1.Grab a copy of the project.

git clone new_project.git

2.Create a virtual environment and install dependencies.

mkvirtualenv new_project pip install -r requirements.txt

3.Duplicate new_project/new_project/local_settings_example.py and save as local_settings.py.

4.Enter your database settings in local_settings.py.

5.Initialize your database.

python ./manage.py syncdb python ./manage.py migrate

6.If your app has a custom user model, you'll need to create a new superuser for the admin.

python ./manage.py createsuperuser

7.Run the development server to verify everything is working.

python ./manage.py runserver

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.