different urls

23 views
Skip to first unread message

gerard

unread,
Nov 9, 2014, 3:50:36 AM11/9/14
to django...@googlegroups.com
Hello all,

i have an application (Django 1.4 LTS) that can be accessed with 2 urls:
the default is https://my.app.org
and the second is http://consult.my.app.org

In the templates, i'm using:
<h1><a href="{% url 'auth_login' %}">{% trans "Connect to see more
features" %}</a></h1>

and it's displayed as https://my.app.org/accounts/login if we access
from https://my.app.org but http://consult.my.app.org/accounts/login if
the second one.

For few href in templates, i need to change the rendreed url, forcing it
to the first form or the second form, not depending on the user experience.
I'm wondering if it is possible to change it in Django (not in apache by
using redirection)? for instance with Sites?
<a href="{% url 'auth_login'|rewrite_url %} ? or something else?

if you browse http://consult.my.app.org/, i want href login to be
https://my.app.org/accounts/login, not
http://consult.my.app.org/accounts/login
or sometimes if user needs events/1352747/ical/, i want to force the
resulting as
http://consult.calendrier.emath.fr/events/1352747/ical/
not https://....


Thans in advance for help,

--
Gérard Henry

Russell Keith-Magee

unread,
Nov 9, 2014, 6:13:40 PM11/9/14
to Django Users
On Sun, Nov 9, 2014 at 4:50 PM, gerard <gh22...@gmail.com> wrote:
Hello all,

i have an application (Django 1.4 LTS) that can be accessed with 2 urls:
the default is https://my.app.org
and the second is http://consult.my.app.org

In the templates, i'm using:
<h1><a href="{% url 'auth_login' %}">{% trans "Connect to see more features" %}</a></h1>

and it's displayed as https://my.app.org/accounts/login if we access from https://my.app.org but http://consult.my.app.org/accounts/login if the second one.

Are you sure about that? The default behaviour of the {% url %} tag doesn't include the domain - it only includes the path. The *browser* will interpret that as a fully qualified URL on the same domain as the current page, but the page itself should only include the "/accounts/login" part.
 
For few href in templates, i need to change the rendreed url, forcing it to the first form or the second form, not depending on the user experience.
I'm wondering if it is possible to change it in Django (not in apache by using redirection)? for instance with Sites?
<a href="{% url 'auth_login'|rewrite_url %} ? or something else?

if you browse http://consult.my.app.org/, i want href login to be https://my.app.org/accounts/login, not http://consult.my.app.org/accounts/login
or sometimes if user needs events/1352747/ical/, i want to force the resulting as
http://consult.calendrier.emath.fr/events/1352747/ical/
not https://....

No rewriting or special tricks are needed - just prepend the domain you want. For example, if you want to always redirect to the "my.app.org" version of the URL, just put that URL as a prefix in the HREF:

<a href="https://my.app.org{% url 'auth_login' %}"> 

If referencing the site is something you're going to be doing more often than just once to point at a login page, you could do something with a context processor to put a specific site into the context for every page, and then reference that site instead of using a string literal in your template.

Hope that helps!

Yours,
Russ Magee %-)
Reply all
Reply to author
Forward
0 new messages