To host a Django website on Render, follow these steps:
1). Sign up for an account on Render: Visit the Render website (https://render.com/) and create a new account if you don't have one already.
2). Create a new web service: Once you're logged in, click on the "Create a New Service" button.
3). Configure your service: In the "Configure Your New Service" section, select the following options:
- Select "Web Service" as the type.
- Choose a name for your service.
- Select the deployment region.
- Choose the appropriate runtime (e.g., Python 3.8).
4). Connect your code repository: In the "Get Code" section, choose the repository where your Django project is hosted (e.g., GitHub, GitLab, Bitbucket). Connect to your repository and select the branch or commit you want to deploy.
5). Set up the build command: In the "Build Command" section, enter the following command:
pip install -r requirements.txt
6). Set up the start command: In the "Start Command" section, enter the following command:
your_project_name with the actual name of your Django project.
7). Configure environment variables (if necessary): If your Django project requires any environment variables, you can add them in the "Environment" section.
8). Specify the port: In the "Port" section, select the appropriate port (usually 80 for HTTP).
9). Deploy your Django website: Click on the "Create Service" button to start the deployment process. Render will build your Django project, install the dependencies, and start the web server.
10). Monitor deployment status: Once the deployment process starts, you can monitor the progress in the Render dashboard. It may take a few minutes for the deployment to complete.
11). Access your Django website: Once the deployment is successful, you will be provided with a URL where your Django website is hosted. You can access your website using that URL.
1). Add the following lines of code to settings.py of your project
STATICFILES_DIRS = [BASE_DIR / "static"] # new STATIC_ROOT = BASE_DIR / "staticfiles" # new
2). in the
urls.py, add the following lines of code:
from django.contrib.staticfiles.urls import staticfiles_urlpatterns # new urlpatterns += staticfiles_urlpatterns() # new