Problem with URL configuration - cannot use absolute URLs in my case

32 views
Skip to first unread message

Rohit Banga

unread,
Oct 6, 2012, 9:25:00 PM10/6/12
to django...@googlegroups.com
Hi

I have a website at example.com/mywebsite. All URL requests directed to this URL are directed to my app.

Now I have the following project structure

   mywebsiteroot/
      -- myapp/
           -- manage.py
           -- myapp/
                 --templates/
                 --settings.py
                 --models.py
                 --views.py


When my base.html template includes a link "mylink" which shows some information.
On the home page this works fine. my django app receives a URL request for example.com/mywebsite/mylink which I serve using base.html template.

Now I extend the base.html template elsewhere in another view mylink/<some_integer>.
In that view the link points to example.com/mywebsite/mylink/mylink which is obviously wrong. If I use an absolute link /mylink; I get a request at example.com/mylink and not example.com/mywebsite/mylink which is also wrong.

So how do I code my url conf / view / template in order to be independent of mywebsite name.
Is there anything wrong with the way I am wiring up my application.

Thanks in Advance!

Ramiro Morales

unread,
Oct 8, 2012, 10:51:29 AM10/8/12
to django...@googlegroups.com
On Sat, Oct 6, 2012 at 10:25 PM, Rohit Banga <iamroh...@gmail.com> wrote:
>
> So how do I code my url conf / view / template in order to be independent of
> mywebsite name.
> Is there anything wrong with the way I am wiring up my application.

Take a look at the docs for:

URL reversing: https://docs.djangoproject.com/en/dev/topics/http/urls/#reverse-resolution-of-urls

Naming URLs: https://docs.djangoproject.com/en/dev/topics/http/urls/#naming-url-patterns

These links point to the in-development version of the docs. This is because
there has been a refactor lately to make presentation of these concepts more
clear and because there hasn't been significant changes in this functionality
since Django 1.4.

HTH

--
Ramiro Morales

Stephen Anto

unread,
Oct 9, 2012, 9:45:31 AM10/9/12
to django...@googlegroups.com
hi,

try to user url name instead of using hard coded url link. it may solve your problem.


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




--
Thanks & Regards
Stephen S



Blog:      blog.f2finterview.com

Reply all
Reply to author
Forward
0 new messages