I want to get absolute url in templates. I can't do with url. It gives me a relative URL. I need to get this:
http://domain.tld/article/post
but Django gives me just
/article/post
I played with settings.py but it didn't work. (debug=false, allowed hosts vs.)
Template code:
{% url 'blog:detail' blog.slug %}
This is easy to do in the view:
If you need to do it in the template, you can probably create your own template tag without too much trouble.
Edit
Assuming that you want to do this in your
Home
view, you could do something like this:Then in your template while you're looping with
{% for postobj in posts %}
you can accesspostobj.post
andpostobj.url
.After a long time meeting with Django, I learned a lot of things. For this issue, I created an absolute URL templatetag.
Add this to your template tags, then use like default url tag:
{% absurl 'some-view' with, arguments %}
Here is the Gist for the absolute URL templatetag, you will need to add request object to template_context_processors, otherwise this will not work. To achieve this, open your settings.py and add these following lines: