views on one page

30 views
Skip to first unread message

Nebros

unread,
Nov 14, 2012, 4:50:04 AM11/14/12
to django...@googlegroups.com
Good morning
I have 2 diffrent views, every one i just needet on one page... till now.
 
view one-----output is the time-----------------
@csrf_protect
def portal(request):
    now = datetime.datetime.now()
    return render_to_response('portal.html', {'current_date': now}, context_instance=RequestContext(request))
---------------------------------------------------------
 
view two-----output are data out of a mssql db--------------
def kundendaten(request):
    cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER=MAURITIUS;DATABASE=baan5c;UID=***;PWD=*****')
    cursor = cnxn.cursor()
    cursor.execute("SELECT x.t_name, y.t_mail FROM tttaad200000 as x, tttcmf200000 as y WHERE (x.t_name = y.t_name) AND (x.t_user = 'niedereh')")
    row = cursor.fetchall()
    return render_to_response("kundendaten.html", { 'row': row }, context_instance=RequestContext(request))
---------------------------------------------------------------------------
 
in addition, i have to set the x.t_user as a variable. the value will be given from the page before. (form/post/submit)
 
how can i use this two now on one page? (i know these are two render_to_response and i cant just use:
{% block content %}<p>Zeit der Aktualisierung {{ current_date }}</p>{% endblock %}
and
{% block content %}<p>Kundendaten {{ row }}.</p>{% endblock %}
on one page)...
 
I just failed by the try to change them...

Martin J. Laubach

unread,
Nov 14, 2012, 5:00:18 AM11/14/12
to django...@googlegroups.com
Do you actually need both as views proper? The easiest thing would be to factor out the fetching part of the kundendaten view, make that return just a dictionary, then call that and update the context in the first view.

Nebros

unread,
Nov 14, 2012, 5:38:26 AM11/14/12
to django...@googlegroups.com
I need both together, because later i need another output from another database (lotus notes (i hate it)) on the same page. Can you make a code for me? im really not good (a new user)... when one part works, maybe i know than how to implements the next database by myself. :)

Nebros

unread,
Nov 15, 2012, 4:03:31 AM11/15/12
to django...@googlegroups.com
Are there not more intput? pls help me, I do not go any further...!

Vibhu Rishi

unread,
Nov 15, 2012, 10:13:14 PM11/15/12
to django...@googlegroups.com
I don't think you can use 2 views on the same page. 

what you can do is pass 2 values to the same page to display. 

so in the 2nd view you will do as follows: 
return render_to_response("kundendaten.html", { 'row': row,'current_date': now }, context_instance=RequestContext(request))

and make sure that you have a variable for now in the 2nd view. 

Hope this helps.

V.


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/Fxv5JtTBvnAJ.

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.



--
Simplicity is the ultimate sophistication. - Leonardo da Vinci
Life is really simple, but we insist on making it complicated. - Confucius

Nebros

unread,
Nov 16, 2012, 3:08:33 AM11/16/12
to django...@googlegroups.com
That was exactly what i have searched for. thank you very mutch. it works now. i post here again my current code, if another needs the same help...
 
views---------------------------------------------
def kundendaten(request):
    cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER=MAURITIUS;DATABASE=baan5c;UID=***;PWD=*****')
    cursor = cnxn.cursor()
    cursor.execute("SELECT x.t_name, y.t_mail FROM tttaad200000 as x, tttcmf200000 as y WHERE (x.t_name = y.t_name) AND (x.t_user = 'niedereh')")
    row = cursor.fetchall()
    now = datetime.datetime.now()

    return render_to_response("kundendaten.html", { 'row': row,'current_date': now }, context_instance=RequestContext(request))
----------------------------------------------------
 
and here a part of my kundendaten.html
kundendaten----------------------------------
<h2>Ausgabe Kundendaten</h2>
{% block content1 %}<p>Zeit der Aktualisierung {{ current_date }}</p>{% endblock %}
{% block content2 %}<p>Kundendaten {{ row }}.</p>{% endblock %}
----------------------------------------------------
 
have a nice day! :)
Reply all
Reply to author
Forward
0 new messages