|
| 1 | +> A batteries-included Django starter project. To learn more try the books [Django for Beginners](https://djangoforbeginners.com), [Django for APIs](https://djangoforapis.com), and [Django for Professionals](https://djangoforprofessionals.com). |
| 2 | +
|
| 3 | +## 🚀 Features |
| 4 | + |
| 5 | +- Django 4.1 & Python 3.10 |
| 6 | +- Install via [Pip](https://pypi.org/project/pip/), [Pipenv](https://pypi.org/project/pipenv/), or [Docker](https://www.docker.com/) |
| 7 | +- User log in/out, sign up, password reset via [django-allauth](https://github.com/pennersr/django-allauth) |
| 8 | +- Static files configured with [Whitenoise](http://whitenoise.evans.io/en/stable/index.html) |
| 9 | +- Styling with [Bootstrap v5](https://getbootstrap.com/) |
| 10 | +- Debugging with [django-debug-toolbar](https://github.com/jazzband/django-debug-toolbar) |
| 11 | +- DRY forms with [django-crispy-forms](https://github.com/django-crispy-forms/django-crispy-forms) |
| 12 | + |
| 13 | + |
| 14 | +---- |
| 15 | + |
| 16 | +## Table of Contents |
| 17 | +* **[Installation](#installation)** |
| 18 | + * [Pip](#pip) |
| 19 | + * [Pipenv](#pipenv) |
| 20 | + * [Docker](#docker) |
| 21 | +* [Next Steps](#next-steps) |
| 22 | +* [Contributing](#contributing) |
| 23 | +* [Support](#support) |
| 24 | +* [License](#license) |
| 25 | + |
| 26 | +---- |
| 27 | + |
| 28 | +## 📖 Installation |
| 29 | +DjangoX can be installed via Pip, Pipenv, or Docker. To start, clone the repo to your local computer and change into the proper directory. |
| 30 | + |
| 31 | +``` |
| 32 | +$ git clone https://github.com/wsvincent/djangox.git |
| 33 | +$ cd djangox |
| 34 | +``` |
| 35 | + |
| 36 | +### Pip |
| 37 | + |
| 38 | +``` |
| 39 | +$ python -m venv .venv |
| 40 | +
|
| 41 | +# Windows |
| 42 | +$ Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser |
| 43 | +$ .venv\Scripts\Activate.ps1 |
| 44 | +
|
| 45 | +# macOS |
| 46 | +$ source .venv/bin/activate |
| 47 | +
|
| 48 | +(.venv) $ pip install -r requirements.txt |
| 49 | +(.venv) $ python manage.py migrate |
| 50 | +(.venv) $ python manage.py createsuperuser |
| 51 | +(.venv) $ python manage.py runserver |
| 52 | +# Load the site at http://127.0.0.1:8000 |
| 53 | +``` |
| 54 | + |
| 55 | +### Pipenv |
| 56 | + |
| 57 | +``` |
| 58 | +$ pipenv install |
| 59 | +$ pipenv shell |
| 60 | +(.venv) $ python manage.py migrate |
| 61 | +(.venv) $ python manage.py createsuperuser |
| 62 | +(.venv) $ python manage.py runserver |
| 63 | +# Load the site at http://127.0.0.1:8000 |
| 64 | +``` |
| 65 | + |
| 66 | +### Docker |
| 67 | + |
| 68 | +To use Docker with PostgreSQL as the database update the `DATABASES` section of `django_project/settings.py` to reflect the following: |
| 69 | + |
| 70 | +```python |
| 71 | +# django_project/settings.py |
| 72 | +DATABASES = { |
| 73 | + "default": { |
| 74 | + "ENGINE": "django.db.backends.postgresql", |
| 75 | + "NAME": "postgres", |
| 76 | + "USER": "postgres", |
| 77 | + "PASSWORD": "postgres", |
| 78 | + "HOST": "db", # set in docker-compose.yml |
| 79 | + "PORT": 5432, # default postgres port |
| 80 | + } |
| 81 | +} |
| 82 | +``` |
| 83 | + |
| 84 | +The `INTERNAL_IPS` configuration in `django_project/settings.py` must be also be updated: |
| 85 | + |
| 86 | +```python |
| 87 | +# config/settings.py |
| 88 | +# django-debug-toolbar |
| 89 | +import socket |
| 90 | +hostname, _, ips = socket.gethostbyname_ex(socket.gethostname()) |
| 91 | +INTERNAL_IPS = [ip[:-1] + "1" for ip in ips] |
| 92 | +``` |
| 93 | + |
| 94 | +And then proceed to build the Docker image, run the container, and execute the standard commands within Docker. |
| 95 | + |
| 96 | +``` |
| 97 | +$ docker-compose up -d --build |
| 98 | +$ docker-compose exec web python manage.py migrate |
| 99 | +$ docker-compose exec web python manage.py createsuperuser |
| 100 | +# Load the site at http://127.0.0.1:8000 |
| 101 | +``` |
| 102 | + |
| 103 | +## Next Steps |
| 104 | + |
| 105 | +- Add environment variables. There are multiple packages but I personally prefer [environs](https://pypi.org/project/environs/). |
| 106 | +- Add [gunicorn](https://pypi.org/project/gunicorn/) as the production web server. |
| 107 | +- Update the [EMAIL_BACKEND](https://docs.djangoproject.com/en/4.0/topics/email/#module-django.core.mail) and connect with a mail provider. |
| 108 | +- Make the [admin more secure](https://opensource.com/article/18/1/10-tips-making-django-admin-more-secure). |
| 109 | +- `django-allauth` supports [social authentication](https://django-allauth.readthedocs.io/en/latest/providers.html) if you need that. |
| 110 | + |
| 111 | +I cover all of these steps in my three books: [Django for Beginners](https://djangoforbeginners.com), [Django for APIs](https://djangoforapis.com), and [Django for Professionals](https://djangoforprofessionals.com). |
| 112 | + |
| 113 | +---- |
| 114 | + |
| 115 | +## 🤝 Contributing |
| 116 | + |
| 117 | +Contributions, issues and feature requests are welcome! See [CONTRIBUTING.md](https://github.com/wsvincent/djangox/blob/master/CONTRIBUTING.md). |
| 118 | + |
| 119 | +## ⭐️ Support |
| 120 | + |
| 121 | +Give a ⭐️ if this project helped you! |
| 122 | + |
| 123 | +## License |
| 124 | + |
| 125 | +[The MIT License](LICENSE) |
0 commit comments