Question

I trying to render values from two function to one html and I not sure how to perform this task. I suppose to use "return render" in both function? and how should be in urls.py to read this both functions? For now I have as is bellow and of course TopAlerts not returning anything. Any suggestions?

views.py

def OneWeekRequest(request):
    #code here....
    ......
    return render_to_response('weeklyreport.html',
                              {'n1week': n1week,
                               'g1week': g1week,
                               'fweeks': fweeks,
                               'g4weeks': g4weeks,
                               'form': form,
                               'start': start,
                               'end': end,
                               'wnumber': wnumber,
                               'speriod': selectedrange},
                              context_instance=RequestContext(request))

def TopAlerts(request):
    #code here....
        ......    
    return render(request, 'weeklyreport.html', {'tops': tops})

urls.py

from django.conf import settings
from django.conf.urls import patterns, include, url

urlpatterns = patterns('',
    url(r'^$', 'platforms.views.queryset'),
    url(r'^weeklyreport/$', 'weeklyreport.views.OneWeekRequest'),
    #url(r'^weeklyreport/', include('weeklyreport.urls')),
Was it helpful?

Solution 2

You can't return two views from one URL. A URL always points to one single view (although of course multiple URLs can point to the same view).

It sounds like your TopAlerts view should really be an inclusion tag.

OTHER TIPS

I created templatetag.py in templatetags

from django import template
from platforms.models import Platform, Event

register = template.Library()

@register.simple_tag
def top_alerts(top):
    tops = Event.objects.filter(sourcetype_id__in=[1, 3],
                                  status_id__in=[1,2,7,8],
                                  event_datetime__range=('2014-04-07', '2014-04-13')
                                  ).exclude(service_id__in=[759, 7]
                                            ).values("event_datetime",
                                                     "platform__name",
                                                     "host__name","service__name",
                                                     "eventtype__name",
                                                     "status__name", "data")
    return {'tops': tops}

and in my template.

{% load templatetag %}
and
{% top_alerts top %}

And is working fine, but i not entirely sure if this goes correct way with my project.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top