I'm trying to make a basic store app. I've set up a database so that every product is tied to a particular store: let's call the stores Shoes, Toys, and Books.. I need to set up subdomains for the app (it's in the assignment specs, no choice there) so that I can map to shoes.myapp.com, toys.myapp.com and books.myapp.com. What I think I need to do is somehow set up the subdomain (which I've googled but am confused about: is this the way to go?) and then, I guess, filter my databases from the info in the subdomain so that only products that have the store name "Shoes" for example appear on the page. Am I anywhere approaching the right track or is there a much better way to structure this?
I suggest you to use this application: django-subdomains. http://django-subdomains.readthedocs.org/en/latest/index.html
And then, in your settings.py, you should use:
SUBDOMAIN_URLCONF = {
'toys': 'yourproject.urls.toys',
'shoes': 'yourproject.urls.shoes'
(...)
}
If you need to use the name of the subdomain in a view, it will be attached to the request object:
def your_view(request):
subdomain = request.subdomain
products = Products.objects.filter(store=subdomain) #an example how to use it to specif database queries. I dont know how your models are
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With