There is a lot of tutorials that explain how to use django and flask, the templatings in both of them are close to each other, maybe, aren't they ??!!
-- So i think if i got an answer doesn't matter flask or django i think it will work, at least that what am thinking dude !!
On Sunday, May 10, 2015 at 6:49:44 PM UTC+6, Reznov Ammar wrote:
On Sunday, May 10, 2015 at 6:49:44 PM UTC+6, Reznov Ammar wrote:
Hi guys :),I have a question about flask and databases in django.
I've had created template for a search form with selects tags like a listbox,
and i also connected it to postgresql database and everything works great.
The question is how i can fetch informations from the database when
just any one choosing one of the choices in the listbox ?
I mean by that, if some one hit the search button it goes and search
for the information that he asked for and showing them down in a ul or
table tag whatever ??
here is my run.py contains:
from flask import Flask, render_template
import datetime
import psycopg2
import sys
reload(sys)
sys.setdefaultencoding("utf-8")
app = Flask(__name__)
@app.template_filter()
def datetimefilter(value, format='%Y/%m/%d %H:%M'):
"""convert a datetime to a different format."""
return value.strftime(format)
app.jinja_env.filters['datetimefilter'] = datetimefilter
@app.route("/")
def template_test():
con = None
try:
con = psycopg2.connect(database='address_test', user='postgres',
password='123123123')
cur = con.cursor()
cur.execute('SELECT id,name_ru,name_kg FROM street_type ORDER BY id DESC')
entries = [dict(id=row[0], name_ru=row[1], name_kg=row[2]) for row in
cur.fetchall()]
except psycopg2.DatabaseError, e:
print 'Error %s' %e
sys.exit(1)
finally:
if con:
con.close()
return render_template('show_entries.html', entries=entries)
also here is my show_entries.html contains :
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery. "></script>min.js
<link rel="stylesheet" type="text/css" href="/static/css/style.css">
<link href='http://fonts.googleapis.com/css?family=Satisfy '
rel='stylesheet' type='text/css'>
<script type=text/javascript>
$SCRIPT_ROOT = {{ request.script_root|tojson|safe }};
</script>
{% block body %}
<div class='header'>
<h1>АДРЕСНЫЙ РЕГИСТР КЫРГЫЗСКОЙ РЕСПУБЛИКИ</h1>
</div>
<div class="logo"></div>
<hr class="horizontal-line" />
<section class="search-form" style="display: block">
<div class="box">
<ul>
<li>
<label>Область/Город республиканского значения</label>
<select id="oblast_select">
<option value="0">нет</option>
<option value="5971">Баткенская Область</option>
<option value="7402">Бишкек</option>
<option value="5219">Джалал-Абадская Область</option>
<option value="4949">Иссык-Кульская Область</option>
<option value="5764">Нарынская Область</option>
<option value="7412">Ош</option>
<option value="6217">Ошская Область</option>
<option value="6802">Таласская Область</option>
<option value="6940">Чуйская Область</option>
</select>
</li>
<li>
<label>Район/Город областного значения</label>
<select id="raion_select">
<option value="0">нет</option>
</select>
</li>
<li>
<label>Айылный аймак/Город районного значения</label>
<select id="ayil_select">
<option value="0">нет</option>
</select>
</li>
<li>
<label>Поселек/ПГТ/Село</label>
<select id="punkt_select">
<option value="0">нет</option>
</select>
</li>
<li>
<label>Территориальная единица</label>
<select id="ter_ed_select">
<option value="0" selected="selected">нет</option>
</select>
</li>
<li>
<label>Территориальный объект</label>
<select id="ter_ob_select">
<option value="0" selected="selected">нет</option>
</select>
</li>
<li>
<label>Тип улицы</label>
<select id="street_type_select">
<option value="0">нет</option>
<option value="7">аллея</option>
<option value="3">бульвар</option>
<option value="5">канал</option>
<option value="14">квартал</option>
<option value="13">контур</option>
<option value="19">кошара</option>
<option value="10">массив</option>
<option value="4">микрорайон</option>
<option value="18">мтф</option>
<option value="1">переулок</option>
<option value="16">площадь</option>
<option value="11">проезд</option>
<option value="2">проспект</option>
<option value="15">разъезд</option>
<option value="12">станция</option>
<option value="8">тупик</option>
<option value="6">улица</option>
<option value="20">урочище</option>
<option value="9">участок</option>
<option value="17">шоссе</option>
</select>
</li>
<li>
<label>Наименование</label>
<input id="street_name" value="" type="text">
</li>
<li>
<a class="btn">Поиск</a>
<a class="btn-msg" href="javascript:void(0)">Сообщить об улице</a>
</li>
</ul>
</div>
</section>
<div class="here"><!-- Results inside ul or table tags-->
</div>
{% endblock %}
Please any help would be tons appreciated :) .
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/bd246c59-e983-4e73-864f-b791568fce52%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment