views:

45

answers:

1

Hi Guys,

I must be suffering from a serious lack of sleep but I am stumped. I can't seem to figure out how to get the {% url %} directive to give me the right url. So let's start with the basics..

urls.py

from people.views import employee_detail

urlpatterns = patterns("",
    url(r'/uid/(?P<id>[0-9]+)/$', employee_detail, {'template_name' : 'people/single.html'}, name = 'employee_view'),
)

views.py

from django.shortcuts import render_to_response, get_list_or_404
from django.template import RequestContext
from people.models import Employee, OfficeLocation

def employee_detail(request, id, template_name = None):
    """
        This will give you a full detailed information on a user
        based off of there name.
    """
    person = Employee.objects.get(id = id)        
    return render_to_response(template_name, _getDetail(person),
                              context_instance = RequestContext(request))

Lastly here is a sample snippet of my people/single.html.

people/single.html

<tr>
<td width="300px">Supervisor: <a href="{% url employee_view , id=supervisor_id %}">{{ supervisor }}</a></td> </tr>

Now I can see that I am passing the right data back and forth. For example this results in a link which in the code looks like

<td width="300px">Supervisor: <a href="//uid/415/">NAME</a></td>

Now what am I doing wrong.. I'm missing the hostname part of the url.. Can someone please tell me how to get back "http://127.0.0.1:8000/uid/415" or whatever the hostname is?

Grr.. It's got to be simple I know I'm suffering from a lac of sleep..

+2  A: 

get_absolute_url is a misnomer, and never returns an absolute (scheme + hostname + port) part. For that aspect of things, you need to use the Sites framework (using Site.objects.get_current()) and get the domain, etc separately.

The naming of the method has raised enough eyebrows that Simon Willison has proposed replacing it entirely.

Keryn Knight
Yeah I saw that too - but never the less my problem remains.. Grr..
rh0dium
So I broke down and used the Sites framework. Once I work through it I'll give you credit. Thanks!!
rh0dium