Using two urls to load the same template

19 views
Skip to first unread message

RLF_UNIQUE

unread,
Nov 14, 2014, 3:37:27 AM11/14/14
to django...@googlegroups.com
Hello,

I'm having this weird situation where if you go to my website like this
vs like this

I'm getting different values.

urls.py
urlpatterns += patterns('',   
      url(r'^index.html$',               views.index,               name='index'),
      url(r'^$',                              views.index,               name='index'),
)

view.py
def index(request):
   home_list = Home.objects.all()[:1]                                                                                                                                                                                                    
   context = {'home_list': home_list}
   return render_to_response('index.html', context)

index.html
{% extends 'base.html' %}                                                                                                                                                                                                               
  {% block content %}
  test
      {% for home in home_list %}
      {{home.description|safe}}
      {% endfor %}
  {% endblock %}

when I just go to mysite.com, I only get "test", whereas when I go to mysite.com/index.html, I get "test" as well as the home variable.

It almost seems like something isn't loading in the proper order?

Thanks
Kyle

RLF_UNIQUE

unread,
Nov 14, 2014, 4:33:29 AM11/14/14
to django...@googlegroups.com
Did some more testing, seems like it's completely skipping the views.py, and going straight to loading index.html, any way to force it to dynamically load?

RLF_UNIQUE

unread,
Nov 14, 2014, 5:03:09 AM11/14/14
to django...@googlegroups.com
I think I figured it out. I was building "in" satchmo and was previously appending my urls to satchmo s, which probably has a catch all handler (r'^$') already that was loading it's own view and rendering index.html but was hitting my (overridden) template without any context since the views handler was different

werefrog

unread,
Nov 14, 2014, 5:26:15 AM11/14/14
to django...@googlegroups.com
Hello Kyle,

I have no clue of what's happening at your Home object request but you
have two urls sharing the same name. You can allow the two urls in the
same pattern like this:

url(r'^(index\.html/)?$', views.index, name='index'),

Here, the group (index\.html/) can be found once or not at all thanks to
the '?'.

Best Regards,
M

Le 14/11/2014 05:33, RLF_UNIQUE a écrit :
> Did some more testing, seems like it's completely skipping the views.py,
> and going straight to loading index.html, any way to force it to
> dynamically load?
>
> On Thursday, November 13, 2014 9:37:27 PM UTC-6, RLF_UNIQUE wrote:
>> Hello,
>>
>> I'm having this weird situation where if you go to my website like this
>> www.mywebsite.com
>> vs like this
>> www.mywebsite.com/index.html
>>
>> I'm getting different values.
>>
>> *urls.py*
>> urlpatterns += patterns('',
>> url(r'^index.html$', views.index,
>> name='index'),
>> url(r'^$', views.index,
>> name='index'),
>> )
>>
>> *view.py*
>> def index(request):
>> home_list = Home.objects.all()[:1]
>>
>>
>>
>> context = {'home_list': home_list}
>> return render_to_response('index.html', context)
>>
>> *index.html*
Reply all
Reply to author
Forward
0 new messages