I have a Django project for a simple blog/forum website I’m building.
I’m using the syndication feed framework, which seems to generate the URLs for items in the feed using the domain of the current site from the Sites framework.
I was previously unaware of the Sites framework. My project isn’t going to be used for multiple sites, just one.
What I want to do is set the domain
property of the current site. Where in my Django project should I do that? Somewhere in /settings.py?
The other answers suggest to manually update the site in the admin, shell, or your DB. That's a bad idea—it should be automatic.
You can create a migration that'll do this automatically when you run your migrations, so you can be assured it's always applied (such as when you deploy to production). This is also recommended in the documentation, but it doesn't list instructions.
First, run
./manage.py makemigrations --empty myapp
to create an empty migration. Then add the following code:Make sure you've set
SITE_ID
in your settings and rename the file to something suitable, such asupdate_site_details.py
. Then run./manage.py migrate
to apply the changes :)You can modify the Site entry in your database manually. Navigate to the table called 'django_site'. Then, you should only see one entry (row). You'll want to modify the field (column) named 'domain'.
If I understand correctly, Sites framework data is stored in the database, so if I want to store this permanently, I guess it’s appropriate in an
initial_data
fixture.I fired up the Django shell, and did the following:
I then grabbed just this data at the command line:
And pasted it into my pre-existing
initial_data
fixture.You can change it using django admin site.
Just go to
127.0.0.1:8000/admin/sites/