Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start an existing Django project?

Tags:

django

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.

like image 514
Keselme Avatar asked Aug 16 '18 05:08

Keselme


1 Answers

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.

like image 95
Deepak Saini Avatar answered Sep 29 '22 07:09

Deepak Saini