If you want to add some interactivity to your existing Django project, you don't have to rewrite it in ReactPy. Use ReactPy-Django to add ReactPy to your existing stack, and render interactive components anywhere.
!!! abstract "Note"
These docs assumes you have already created [a **Django project**](https://docs.djangoproject.com/en/stable/intro/tutorial01/), which involves creating and installing at least one **Django app**.
If do not have a **Django project**, check out this [9 minute YouTube tutorial](https://www.youtube.com/watch?v=ZsJRXS_vrw0) created by _IDG TECHtalk_.
Run the following command to install reactpy-django
in your Python environment.
pip install reactpy-django
Add #!python "reactpy_django"
to INSTALLED_APPS
in your settings.py
file.
=== "settings.py"
```python
{% include "../../examples/python/configure_installed_apps.py" %}
```
??? warning "Enable ASGI and Django Channels (Required)"
ReactPy-Django requires Django ASGI and [Django Channels](https://github.com/django/channels) WebSockets.
If you have not enabled ASGI on your **Django project** yet, here is a summary of the [`django`](https://docs.djangoproject.com/en/stable/howto/deployment/asgi/) and [`channels`](https://channels.readthedocs.io/en/stable/installation.html) installation docs:
1. Install `channels[daphne]`
2. Add `#!python "daphne"` to `#!python INSTALLED_APPS`.
```python linenums="0"
{% include "../../examples/python/configure_channels_installed_app.py" %}
```
3. Set your `#!python ASGI_APPLICATION` variable.
```python linenums="0"
{% include "../../examples/python/configure_channels_asgi_app.py" %}
```
??? info "Configure ReactPy settings (Optional)"
ReactPy's has additional configuration available to fit a variety of use cases.
See the [ReactPy settings](../reference/settings.md) documentation to learn more.
Add ReactPy HTTP paths to your #!python urlpatterns
in your urls.py
file.
=== "urls.py"
```python
{% include "../../examples/python/configure_urls.py" %}
```
Register ReactPy's WebSocket using #!python REACTPY_WEBSOCKET_ROUTE
in your asgi.py
file.
=== "asgi.py"
```python
{% include "../../examples/python/configure_asgi.py" %}
```
??? info "Add #!python AuthMiddlewareStack
(Optional)"
There are many situations where you need to access the Django `#!python User` or `#!python Session` objects within ReactPy components. For example, if you want to:
1. Access the `#!python User` that is currently logged in
3. Access Django's `#!python Session` object
2. Login or logout the current `#!python User`
In these situations will need to ensure you are using `#!python AuthMiddlewareStack`.
```python linenums="0"
{% include "../../examples/python/configure_asgi_middleware.py" start="# start" %}
```
??? question "Where is my asgi.py
?"
If you do not have an `asgi.py`, follow the [`channels` installation guide](https://channels.readthedocs.io/en/stable/installation.html).
Run Django's migrate
command to initialize ReactPy-Django's database table.
python manage.py migrate
Run Django's check
command to verify if ReactPy was set up correctly.
python manage.py check
The next page will show you how to create your first ReactPy component.
Prefer a quick summary? Read the At a Glance section below.
!!! info "At a Glance"
<font size="5">**`my_app/components.py`**</font>
{% include-markdown "../../../README.md" start="<!--py-header-start-->" end="<!--py-code-end-->" %}
---
<font size="5">**`my_app/templates/my_template.html`**</font>
{% include-markdown "../../../README.md" start="<!--html-header-start-->" end="<!--html-code-end-->" %}