# 🚀 Day 10: Django Deployment – Beginner’s Web Dev Series

Welcome to the **final day (Day 10)** of your Django web development journey!

Today, we’ll make your project publicly accessible on the internet by deploying it to **Render.com**, a free and beginner-friendly platform for hosting Django apps.

---

## 📍 What You’ll Learn

1. Preparing your Django app for production
    
2. Creating `requirements.txt` with Gunicorn
    
3. Setting up environment variables with `python-decouple`
    
4. Using `collectstatic` for static file handling
    
5. Connecting your GitHub repo to Render
    

---

## 🔧 1. Prepare Your Project for Deployment

Install Gunicorn for production-ready server handling:

```bash
pip install gunicorn
```

Then freeze dependencies:

```bash
pip freeze > requirements.txt
```

---

## 🛠️ 2. Use `python-decouple` for Environment Variables

### Install it:

```bash
pip install python-decouple
```

### Update `settings.py`:

```python
from decouple import config

SECRET_KEY = config("SECRET_KEY")
DEBUG = config("DEBUG", cast=bool, default=False)
ALLOWED_HOSTS = ["*"]
```

### Create `.env` :

```css
SECRET_KEY=your-secret
DEBUG=False
```

And also create `.env.example`:

```css
DEBUG=False
SECRET_KEY=changeme
```

---

## ⚙️ 3. Update `settings.py, urls.py` for Static, Media Files

```python
# settings.py
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')

# urls.py
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
```

---

## 📁 4. Add `.gitignore`

```txt
*.pyc
__pycache__/
.env
staticfiles/
db.sqlite3
```

---

## 🔃 5. Add `collectstatic` to Your Flow

Make sure this is ready in your production setup:

```bash
python manage.py collectstatic
```

> This command copies all static files to `STATIC_ROOT`, so they can be served in production.

---

## 🛠️ 6. Push to GitHub

```bash
git init
git add .
git commit -m "Prepare for Render deployment"
git remote add origin https://github.com/yourusername/yourproject.git
git push -u origin main
```

---

## 🌐 7. Deploy on Render

1. Visit [https://render.com](https://render.com/)
    
2. Create a free account
    
3. Click **New Web Service**
    
4. Connect your GitHub repo
    
5. Select the repo
    
6. Wait for it to build and deploy (~3–5 mins)
    

---

## ✅ Task for Day 10

* Create a `.env`, `.env.example`, and `requirements.txt`
    
* Add Gunicorn to the project
    
* Push your code to GitHub
    
* Deploy to Render
    
* Share your live link with your team/community!
    

---

## 🏁 You Did It!

🎉 Congratulations on completing the **10-Day Django Beginner Series**!

You now know how to:

* Build dynamic views and templates
    
* Work with models and forms
    
* Handle authentication
    
* Build RESTful APIs
    
* And deploy your Django app to the web
    

## 🧑‍💻 **Beginner Resources**

### 1\. **Official Django Documentation**

* 📚 [https://docs.djangoproject.com](https://docs.djangoproject.com/)
    
* Best place to learn the *right* way
    
* Check out the [official tutorial](https://docs.djangoproject.com/en/stable/intro/tutorial01/)
    

### 2\. **MDN Django Tutorial (by Mozilla)**

* 🔗 [https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django](https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django)
    
* Teaches Django through a practical "Library Catalog" app
    

### 3\. **Real Python Django Series**

* 🔗 [https://realpython.com/tutorials/django/](https://realpython.com/tutorials/django/)
    
* Clear, beginner-to-advanced tutorials with great examples
    

### 4\. **Django for Beginners Book (by William S. Vincent)**

* 🔗 [https://djangoforbeginners.com/](https://djangoforbeginners.com/)
    
* Great for beginners building real-world projects step-by-step
    

---
