0

I would like to create django sites in runtime, using the same settings.py

For example, I have in my django_site table the following rows,

1 | 127.0.0.1:8001 | sitea
2 | 127.0.0.1:8002 | siteb
3 | 127.0.0.1:8003 | sitec

My django goes to my settings.py, fetchs the site_id and brings the right site.. What I would like to do is:

1 | 127.0.0.1:8001 | genericsite

but then the user access:

127.0.0.1:8001/sitea -> it brings sitea
127.0.0.1:8001/siteb -> it brings siteb

How would you go about setting up your urlpatterns? For instance, if I go to my admin page again, create a sited, I should be able to access sited. P.s. All the info I need after that will be filtered based on the site the user is requesting..

I really need a hand with this! Thanks a lot..

bobleujr
  • 1,179
  • 1
  • 8
  • 23

1 Answers1

0

I suggest you to look at django-subdomains.

While it manages different sites as sitea.127.0.0.1:8001, siteb.127.0.0.1:8001 etc unlike you want but you really can check their SubdomainURLRoutingMiddleware to inspirate yourself. And may be subdomains is just what you want :)

It also contains helpful template tags, adds subdomains to request variable and many other goodies.

valignatev
  • 6,020
  • 8
  • 37
  • 61