[Answered ]-Using django subdomain and it says localhost does not belong to the domain example.com

2👍

SITE = 1 will correspond to the default example.com set by django.contrib.site.

django.contrib.sites registers a post_migrate signal handler which creates a default site named example.com with the domain example.com. This site will also be created after Django creates the test database.

This is stored in the DB so there’s no way to set this purely in config.

To set it in the DB, follow the steps here:

>>> from django.contrib.sites.models import Site
>>> one = Site.objects.all()[0]
>>> one.domain = 'myveryspecialdomain.com'
>>> one.name = 'My Special Site Name'
>>> one.save()

Then you can run python manage.py dumpdata sites which produces a JSON of the data you’ve just loaded. Then later load it using django-admin loaddata fixture [fixture ...]. Otherwise you can set it via the admin interface, under the Site app.

List of Django Apps

This will display as example.org before it’s fixed:

The existing site

Change these:

Change the two fields

That should fix the issue.

1👍

Why have you set SITE_ID = 1?

From the Django Docs for django.contrib.site:

django.contrib.sites registers a post_migrate signal handler which creates a default site named example.com with the domain example.com. This site will also be created after Django creates the test database.

You need to specify the correct SITE_ID for your current site.

-1👍

What do I need to change so I can access the BlogListView at
http://localhost:8000/posts/2016/07/09 ? Or better via the actual
subdomain of blog.creativeflow.com

I’ve set up my linode with subdomains pointed to different apps and sites. I did this by configuring NGINX webserver and uWSGI web app daemon in “emperor” mode.

To test django-subdomain locally this question on adding subdomains to localhost may help.

Leave a comment