Question

I have a Django application that exists with complete functionality in both a development and production environment. This is handled by just changing ALLOWED_HOSTS appropriately (assuming you don't want to DEBUG) and setting up Apache to serve each location properly. My issue is that I want to use the Django redirects app to handle my redirects moving forward (a part of this project is a transition away from PHP) because it means I don't need to deal with these redirects in Apache anymore. Redirects are a larger headache and Apache causes issues with its index.php redirect loops. Also this will allow me to transition more website control under Django, which is a goal for management ease. The problem I am encountering is the redirects app uses the SITE_ID to determine a valid target/redirect. The production server has a different hostname than development so I can not test or verify the redirects app. This obviously hurts the purpose of the isolated nearly-identical development server, which is to test all functionality before going live. I understand from the sites framework that individual sites need individual settings.py files and daemons to co-exists, but that again is not helpful to my scenario since the development site is geographically separate from production. It is not clear to me from the documentation:

1) How to add a site, other than adding/altering SITE_ID - where do I choose the associated name?

2) Assuming 1, is that the best way (and is adequate) since I already have a different settings.py file?

3) How did I end up with two sites entries for the same foo.com and how does this affect my redirects? I only have a single wsgi and settings.py (on each server) but

+----+-------------+-------------+
| id | domain      | name        |
+----+-------------+-------------+
|  1 | example.com | example.com |
|  2 | foo.net     | foo.net     |
|  3 | foo.net     | foo         |
+----+-------------+-------------+

in my database? I don't see where these sites are added or configured which is leading to my confusion about how to adjust my sites framework to fit the redirects app. Since I am on Django 1.5.4 the sites framework was enabled by default so I've never even thought about it before.

Was it helpful?

Solution

The name of the associated site does not matter since redirects just uses id, so I deleted all duplicate sites leaving just id 1 for the actual domain name, set SITE_ID = 1 in both production and testing configuration. I do not know where the other sites came from since I only used SITE_ID to set up redirects, but it works now.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top