Re: model get_absolute_url strange behaviour

2009-08-18 Thread andreas schmid

Daniel Roseman wrote:
> On Aug 18, 11:08 am, andreas schmid  wrote:
>   
>> hi to all,
>>
>> i have a weird problem with my urls.
>>
>> my model has a get_absolute_url like this:
>>* def get_absolute_url(self):
>> return "%s/%s/" %  (self.pub_date.strftime("%Y"), self.slug )*
>>
>> and the url conf is this one:
>>  *(r'^(?P\d{4})/(?P[-\w]+)/$',
>> 'myapp.views.projects.project_detail', ),
>> *
>> which works fine... my projects urlconf setup is:
>> *(r'^projects/', include('myapp.urls.projects')),
>>
>> *i set up a form template to add projects without touching the admin
>> interface which works fine too but when i save and it should direct to
>> the project detail view it sets up the url in the wrong way.
>>
>> *return HttpResponseRedirect(new_project.get_absolute_url())
>>
>> *the return above is in my add function but it redirects from
>> *http://mysite.com/add/*to *http://mysite.com/add/2009/slug/*which
>> obviously doesnt work instead of *http://mysite.com/projects/2009/slug/
>> *which works.
>>
>> any help?
>> 
>
> The string returned from your get_absolute_url method would be
> something like "2009/slug/". Because it doesn't start with a slash,
> browsers interpret it as relative to the current URL, so if you start
> on "/add/" it will just add the slug on to that, ending up with "/add/
> 2009/slug/".
>
> Easy to fix - just make sure get_absolute_url starts with a slash:
> return "/%s/%s/" %  (self.pub_date.strftime("%Y"), self.slug )
>
>   
if i put the trailing slash it does not add the projects/ prefix i added
in the include of my projects urls.py ... the problem of the wrong
absolute url is only when i add or edit a project and it doesnt redirect
right... i postet it wrong before, it tryes to redirect at
http://127.0.0.1:8000/projects/add/2009/slug/ without trailing slash in
in the get_absolute_url but every other absolute url in the templates
works fine.
if i put the trailing slash the url is wrong everywhere and links to
http://127.0.0.1:8000/2009/slug/

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: model get_absolute_url strange behaviour

2009-08-18 Thread Daniel Roseman

On Aug 18, 11:08 am, andreas schmid  wrote:
> hi to all,
>
> i have a weird problem with my urls.
>
> my model has a get_absolute_url like this:
>    * def get_absolute_url(self):
>         return "%s/%s/" %  (self.pub_date.strftime("%Y"), self.slug )*
>
> and the url conf is this one:
>  *(r'^(?P\d{4})/(?P[-\w]+)/$',
> 'myapp.views.projects.project_detail', ),
> *
> which works fine... my projects urlconf setup is:
>     *(r'^projects/', include('myapp.urls.projects')),
>
> *i set up a form template to add projects without touching the admin
> interface which works fine too but when i save and it should direct to
> the project detail view it sets up the url in the wrong way.
>
> *return HttpResponseRedirect(new_project.get_absolute_url())
>
> *the return above is in my add function but it redirects from
> *http://mysite.com/add/*to *http://mysite.com/add/2009/slug/*which
> obviously doesnt work instead of *http://mysite.com/projects/2009/slug/
> *which works.
>
> any help?

The string returned from your get_absolute_url method would be
something like "2009/slug/". Because it doesn't start with a slash,
browsers interpret it as relative to the current URL, so if you start
on "/add/" it will just add the slug on to that, ending up with "/add/
2009/slug/".

Easy to fix - just make sure get_absolute_url starts with a slash:
return "/%s/%s/" %  (self.pub_date.strftime("%Y"), self.slug )

--
DR.
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



model get_absolute_url strange behaviour

2009-08-18 Thread andreas schmid

hi to all,

i have a weird problem with my urls.

my model has a get_absolute_url like this:
   * def get_absolute_url(self):
return "%s/%s/" %  (self.pub_date.strftime("%Y"), self.slug )*

and the url conf is this one:
 *(r'^(?P\d{4})/(?P[-\w]+)/$',
'myapp.views.projects.project_detail', ),
*
which works fine... my projects urlconf setup is:
*(r'^projects/', include('myapp.urls.projects')),

*i set up a form template to add projects without touching the admin
interface which works fine too but when i save and it should direct to
the project detail view it sets up the url in the wrong way.

*return HttpResponseRedirect(new_project.get_absolute_url())

*the return above is in my add function but it redirects from
*http://mysite.com/add/* to *http://mysite.com/add/2009/slug/* which
obviously doesnt work instead of *http://mysite.com/projects/2009/slug/
*which works.

any help?


--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---