4. Setup Project

Naturally, we need a django project setup. Let’s do that here.

4.1. Activate Virtual Environment

We did this Using Virtual Environments but here’s a recap:

cd path/to/virtualenv/dir/

mac/linux

source bin/activate

windows

.\Scripts\activate

4.2. Install Required Packages

The required packages are:

To install:

pip install django==3.1.2 celery redis django-celery-beat django-celery-results

If you’re using pipenv: pipenv install django==3.1.2 celery redis django-celery-beat django-celery-results

If you’re working in jupyter (not recommended at this point in the project): !pip install django==3.1.2 celery redis django-celery-beat django-celery-results

4.2.1. Install Packages for the web scraping portion of this book:

  • requests docs - making http requests

  • requests-html docs - parsing HTML content

pip install requests requests-html

We are only using requests-html as an HTML parser in case you need to use a different HTML parser (ie BeautifulSoup, regular expressions, etc). requests-html is capable of performing an HTTP request and parsing the result.

Now save a requirements.txt file:

python -m pip freeze > requirements.txt

4.3. Start Django Project

django-admin startproject time_tasks .

Let’s confirm it’s installed:

ls

Result should be:

manage.py time_tasks requirements.txt

You may see virtual environment files and folders as well. requirements.txt was created above.

If you don’t see manage.py it’s probably because the command you ran was: django-admin startproject time_tasks without the trailing .

4.4. Create Django App

We will implement this app in a few chapters but for now, run this:

python manage.py startapp stocks

4.5. Update time_tasks/settings.py

# time_tasks/settings.py
INSTALLED_APPS += [
    'stocks,
]