This repository contains a Django project template that is optimized for deployment on Liara. It provides a basic setup for a Django project that can easily be deployed to Liara's cloud infrastructure. The project includes integration with PostgreSQL, environment variable management, and support for static and media file handling.
- Django Setup: A basic Django project ready for production deployment.
- PostgreSQL Integration: PostgreSQL configuration for production database use.
- Static and Media Files Handling: Pre-configured static and media file management for production.
- Environment Variables: Use of
.env
file to securely manage configuration. - Deployment on Liara: Optimized for deployment on Liara without Docker.
- Python 3.8+
- Liara CLI: Install Liara CLI
- PostgreSQL: PostgreSQL for production database storage.
-
Clone the repository:
git clone https://github.com/shahramsamar/Django_template_for_deploment_in_liara.git cd Django_template_for_deploment_in_liara
-
Set up your environment variables:
Create a
.env
file in the root directory with the following environment variables:SECRET_KEY=your-django-secret-key DEBUG=False ALLOWED_HOSTS=your-liara-domain.ir DATABASE_URL=postgres://username:password@host:port/database_name
Replace the placeholder values with your actual configuration details.
-
Install dependencies:
Create a virtual environment and install the required dependencies:
python -m venv venv source venv/bin/activate # On Windows, use `venv\Scripts\activate` pip install -r requirements.txt
-
Run migrations:
Apply database migrations:
python manage.py migrate
-
Collect static files:
Prepare static files for production:
python manage.py collectstatic
-
Install Liara CLI
If you haven’t already, install the Liara CLI tool following the installation guide.
-
Log in to Liara
Log in to your Liara account using the following command:
liara login
-
Create a
liara.json
fileCreate a
liara.json
file in the root directory with the following content:{ "type": "python", "name": "your-app-name" }
-
Deploy the application
Deploy your Django app to Liara:
liara deploy
After deployment, your app will be live on your Liara domain.
To use PostgreSQL, follow the steps in the Liara PostgreSQL Guide to create a PostgreSQL database and update your .env
file with the correct DATABASE_URL
format.
Ensure that your settings.py
is correctly configured to handle static and media files for production:
# settings.py
import os
from pathlib import Path
BASE_DIR = Path(__file__).resolve().parent.parent
STATIC_URL = '/static/'
STATIC_ROOT = BASE_DIR / 'staticfiles'
MEDIA_URL = '/media/'
MEDIA_ROOT = BASE_DIR / 'media'
