Django database routing file location

859 Views Asked by At

The Django project I'm currently working on requires that I use a database router. However, the docs page on multiple databases doesn't specify whether a router should be defined in a routers.py file or if it should be stored in urls.py instead.

I've been finding a lot of conflicting information on this, especially when it comes to best practices (there are a lot of different sources, and none of them talk about database routers).

So I'd like to know: where should my database routers actually be declared, and if this is in a separate file, where within my project should this file live (or does it even matter)?

Thanks.

1

There are 1 best solutions below

0
On

In the application directory. Using the Django tutorial as an example, polls/routers.py

mysite/
manage.py
mysite/
    __init__.py
    settings.py
    urls.py
    wsgi.py
polls/
__init__.py
admin.py
apps.py
migrations/
    __init__.py
models.py
tests.py
views.py
routers.py