Tuesday, June 26, 2012

Re: base_url() in django

We understand the issue. You want to display absolute URL including the hostname and protocol in your templates. That's not difficult to do, you just need to write a custom template tag to do this. There's many ways to go about doing this -- however, if you're only running a single web-site on this Django application, I recommend creating a a base URL configuration option in your settings.py and using that for generating the full URL.

The case we're trying to make is -- why do that? Just like Raitucarp said, using an absolute path provides the same end-result as including the hostname and protocol. There's only a few cases where you'd want to do that -- primarily when trying to create links that will be used externally (for example, a "copy and paste link" or for email templates). 

Also, you mention {% url ... %} does relative paths. It doesn't. It does absolute. It just doesn't include the hostname and protocol. A relative path would not begin with a leading "/".

Good luck!

On Tue, Jun 26, 2012 at 3:58 AM, Raitucarp <ribhararnus.pracutiar@gmail.com> wrote:

Is this an actual issue? You realize that there's no difference between
/doc/ and http://example.com/doc/ if the current server is
http://example.com/?

See here:
https://docs.djangoproject.com/en/1.4/ref/templates/builtins/#url

No no, that's not my issue. {% url %} template tag just create relative url that represent the views url. But, what I am going to ask here is create absolute url path. I mean in codeigniter I just call base_url() to create the base url where I am work. In django, it's hard to do that, just it.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/cinsOV4C4fMJ.

To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment