What Did I Do Right? (url and domain name change)

50 views
Skip to first unread message

Malik Rumi

unread,
Aug 6, 2015, 9:03:16 PM8/6/15
to Django users
I have 1 model from my django project up and running on django. Before adding more models and content, I wanted to use my actual domain name, instead of whatever.herokuapp.com. So after I got that straight, I realized that while the home page was mysite.com, the links were still mystite.herokuapp.com, which I think is a problem. But I also thought there had to be an easy fix for this, especially after I saw a post while I was searching for solutions that said django only cares about the stuff that comes after the domain name. So the first thing I did was change a hardcoded link in my navbar from mysite.herokuapp/newpage to mysite/newpage in my dev site. But testing it the url still said mysite.herokuapp.com/newpage. Then I got an idea, and I just manually changed the url to mysite/newpage and what do you know, it came up correctly. then I clicked around and suddenly all the pages on my model are coming up that way, which they were not half an hour ago. So the question: What did I do right?

Here are my working theories:

1. The dns change, which I also did half an hour ago, worked for the home page immediately (I tested it at the time) but needed to propagate more for the other pages to work, which they do now.

2. By changing the url manually, django just fed the pages as requested without concern about the domain part of the url. If I start from mysite.herokuapp.com home page, the links still come up with that domain name.

But how do I make this both universal and permanent?

A. I could change allowed hosts setting, taking the herokuapp part out

B. Do nothing, it works now and I should leave well enough alone.

C. ????? Your answer here ...


Thanks

Bill Freeman

unread,
Aug 6, 2015, 9:41:26 PM8/6/15
to django-users
Look at "Sites" in the admin.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3ded9a89-b20f-489d-aadb-667ab62fdb53%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Aaron C. de Bruyn

unread,
Aug 6, 2015, 10:42:14 PM8/6/15
to django...@googlegroups.com
1. DNS doesn't really work that way in most situations. Your browser
should cache it, your computer should cache it (especially Windows),
and your upstream DNS (usually your router) should cache it. Your
computer literally stores 'mysite.com' = '1.2.3.4'. It doesn't store
it per-page, but for the whole domain name.

2. How are the URLs generated in your application? If your HTML
template literally has: <A HREF="http://mysite.herokuapp.com/{% url
'home' %}">Home page</A>....then the only way to update the URLs for
your app would be to edit the template and fix them. If you are
relying on django-sites to 'know' the base URL for your site, go into
the admin section and click on 'Sites'. I think it's best practice to
not prefix my URLs with http://whatever... Just use {% url 'home' %}
as it should return something like '/' for the URL (without
http://mysite.com).

A. Your ALLOWED_HOSTS setting should probably have both domains if you
want your transition to be smooth. (i.e. the site works through both
URLs). ALLOWED_HOSTS has no affect on what URLs you application
displays.

B. Definitely not. Tweak, break, learn. ;)

Hope that helps.

-A

Malik Rumi

unread,
Aug 7, 2015, 2:56:08 PM8/7/15
to django...@googlegroups.com
I like the 'definitely not' to the do nothing option. Thanks to both of you!

You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/OMkN_I__30Y/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
Reply all
Reply to author
Forward
0 new messages