implement of view

25 views
Skip to first unread message

Markus Christen

unread,
Oct 24, 2012, 10:05:50 AM10/24/12
to django...@googlegroups.com
Hi all
i have there a little problem and my knowhow with django is not existent. ^^
What i have...
--------------- urls.py -----------------
from django.conf.urls import patterns, include, url
from klasse.views import portal, sql
urlpatterns = patterns('',
 (r'^portal/$', portal),
 (r'^sql/$', sql),
)
-----------------------------------------
------------ views.py ----------------
from django.shortcuts import render_to_response
import datetime
def portal(request):
    now = datetime.datetime.now()
    return render_to_response('portal.html', {'current_date': now})
 
def sql(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 = '***')")
 row = cursor.fetchall()
 return HttpResponse(row)
---------------------------------------
 
The Settings are correct... The output of sql works
 
------------------------------------- portal.html --------------------------------
{% extends "base.html" %}
{% block title %}Kundendaten{% endblock %}
{% block content %}<p>Zeit der Aktualisierung {{ current_date }}.</p>{% endblock %}
-------------------------------------------------------------------------------------
 
------------------------------- base.html ---------------------------------------
{% include "header.html" %}
    <title>{% block title %}{% endblock %}</title>
</head>
<body>
    <h1>Portal</h1>
 <h2>Ausgabe Kundendaten</h2>
    {% block content %}{% endblock %}
{% include "footer.html" %}
-------------------------------------------------------------------------------------
 
how can i implements now these "def sql(request):" into my html code? pls help me...

Markus Christen

unread,
Oct 24, 2012, 10:08:46 AM10/24/12
to django...@googlegroups.com
I forgot, sql is now hardcodet and i have to change it. on first page i have to give the filter and the username...

Tomas Neme

unread,
Oct 24, 2012, 10:15:51 AM10/24/12
to django...@googlegroups.com
>
> how can i implements now these "def sql(request):" into my html code? pls
> help me...
>

you're saying next to nothing, but I *guess* you could do something like

return render_to_response("sql.html", { 'row': row })

at the bottom of your sql view, and write an sql.html template that
shows it the way you want...

Also, you'll better go on and learn that pyodbc library and how to
pass parameters into your queries, which will protect you against SQL
injection attacks.. and you should probably learn SOME python if
you're going to be coding in it.

And you shuold *really* at least run through the django tutorial at
least once, in order to get a grip on some of the basic django
concepts, like forms and models, which will help you a lot

--
"The whole of Japan is pure invention. There is no such country, there
are no such people" --Oscar Wilde

|_|0|_|
|_|_|0|
|0|0|0|

(\__/)
(='.'=)This is Bunny. Copy and paste bunny
(")_(") to help him gain world domination.

Markus Christen

unread,
Oct 24, 2012, 10:39:46 AM10/24/12
to django...@googlegroups.com
Thank you for your answer. i have chapter 1-4 of http://www.djangobook.com/en/2.0/index.html done, but not much time to go throught the hole book atm. i will try it with your code. :)

Tomas Neme

unread,
Oct 24, 2012, 10:48:13 AM10/24/12
to django...@googlegroups.com
>> Thank you for your answer. i have chapter 1-4 of
>> http://www.djangobook.com/en/2.0/index.html done, but not much time to go
>> throught the hole book atm. i will try it with your code. :)

the django book is somewhat outdated, and long.

https://docs.djangoproject.com/en/dev/intro/tutorial01/

do that tutorial, it's quite short, you can get through it in a couple of hours.

Markus Christen

unread,
Oct 25, 2012, 12:59:16 AM10/25/12
to django...@googlegroups.com
Thank you for this page. I take my time today, to learn on it. :)
Message has been deleted
Message has been deleted

Markus Christen

unread,
Oct 25, 2012, 8:26:40 AM10/25/12
to django...@googlegroups.com
How can i create 2 views on one page?
def sql(request): and def portal(request): 
 

Tomas Neme

unread,
Oct 25, 2012, 8:54:45 AM10/25/12
to django...@googlegroups.com
>>> How can i create 2 views on one page?
>>> def sql(request): and def portal(request):

You can't. A View *is* a page. Do the tutorial.

You could use class-based views and have a view that inherits from
both, and combines the contexts (this is _not_ in the tuto)
Reply all
Reply to author
Forward
0 new messages