Functions/Views

Hello!

This is probably a really dumb question. However i just started python and django. So please spare me :slight_smile:

I have created two views, and i would them to be displayed at the same page.

Can somebody please point me in the right direction?

Views:

def index(request):

shopping_list = Shopping.objects.order_by('shop_date')

template = loader.get_template('Home_Control/base.html')

context = {

    'shopping_list': shopping_list,

}

return HttpResponse(template.render(context, request))

def home(request):

response = requests.get('http://ip.jsontest.com/')

geodata = response.json()

return render(request, 'Home_Control/base.html', {

    'ip': geodata['ip']

})

urls:

urlpatterns = [

path('', views.index, name='index'),

path('', views.index, name='home'),

] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

It’s not possible to have two views displayed at the same URL. Django will only match and run one. You’ll need to combine the code and templates if you want to show both sets of data and HTML.

Thanks! So would that mean that i have to combine the functions? And the render that to one Template?

Indeed :slight_smile: