Running an existing Django app locally involves similar steps across different operating systems but with some notable differences, especially when setting up the environment and dealing with system-specific commands. Below is a detailed guide.
- Python: Ensure you have Python installed. Django supports Python 3.6 and above.
- pip: This is Python's package installer. It usually comes with Python.
- Virtual Environment: Highly recommended for Python projects to manage dependencies.
- Command Line Interface: Windows uses Command Prompt or PowerShell, while Mac/Linux uses Terminal.
- Path Variables: Sometimes, you may need to add Python or other executables to your system's PATH. The process differs between Windows and Mac/Linux.
- Commands: Some commands differ slightly, e.g., activating a virtual environment.
First, clone the repository containing the Django project to your local machine. Use Git for this purpose.
$ git clone https://github.com/nax3t/django-static-site-optimization.git
$ cd django-static-site-optimization
- Windows
$ python -m venv myenv
$ myenv\Scripts\activate
- Mac/Linux
$ python3 -m venv myenv
$ source myenv/bin/activate
Ensure you are in the project root (where requirements.txt
is located) and run:
$ pip install -r requirements.txt
DEBUG should be True in development, False in production. SECRET_KEY can be generated using the following command:
$ python manage.py shell -c 'from django.core.management import utils; print(utils.get_random_secret_key())'
You can rename the example.env
file in the project root directory to be .env
then set your environment variables there.
Apply the database migrations to set up your database schema:
$ python manage.py migrate
Finally, run the development server:
python manage.py runserver
Your Django app should now be accessible from http://127.0.0.1:8000/
or http://localhost:8000/
.
Visit Cloudinary and sign up for a free account. You can find your Cloudname, API Key, and API Secret in the Dashboard after logging in.
- Watch a video walkthrough
- Get started by uploading a zip file of your static website. Be sure to include your Cloudinary credentials.
- Ensure all the necessary environment variables are set
- Check the Django app settings for any specified host or port changes.
- Make sure your Python and pip are correctly installed and accessible via your terminal or command prompt.
- Always activate your virtual environment before working on your project to isolate dependencies.