Send data back to a table from template or send back to a view

48 views
Skip to first unread message

Coulson Thabo Kgathi

unread,
Oct 24, 2012, 6:05:56 AM10/24/12
to django...@googlegroups.com
Please help i have send a dictionary to a template now i want to send the processed data back to the database how do i do that in template language or javascript

Daniel Roseman

unread,
Oct 24, 2012, 8:16:24 AM10/24/12
to django...@googlegroups.com
On Wednesday, 24 October 2012 07:05:56 UTC+1, Coulson Thabo Kgathi wrote:
Please help i have send a dictionary to a template now i want to send the processed data back to the database how do i do that in template language or javascript

Templates don't process data.

Do you mean to use a form?
--
DR. 

Stephen Anto

unread,
Oct 24, 2012, 8:47:02 AM10/24/12
to django...@googlegroups.com
Hi,

Are you meant form submission? if Yes...

Submit your form and get all submitted values in view method using request.POST/GET.copy()

Thank you for visiting http://www.f2finterview.com/web/Django/

On Wed, Oct 24, 2012 at 11:35 AM, Coulson Thabo Kgathi <zeec...@gmail.com> wrote:
Please help i have send a dictionary to a template now i want to send the processed data back to the database how do i do that in template language or javascript

--
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/-/aSAzhnVceMQJ.
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.



--
Thanks & Regards
Stephen S



Blog:      blog.f2finterview.com

Coulson Thabo Kgathi

unread,
Oct 24, 2012, 9:22:13 AM10/24/12
to django...@googlegroups.com
i had an array of coordinated tht i got from a dictionary via a view in views.py

now i used a javascript function in the template called index.html to find coordinates that are in a polygon

and i want to send the list of those coordinates back to the view so that i ca save them into a table.

views.py

# Import django modules
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.template.loader import render_to_string
from django.core.urlresolvers import reverse
from django.contrib.gis.geos import Point
from django.contrib.gis.gdal import DataSource
# Import system modules
import simplejson
import itertools
import tempfile
import os
import MySQLdb
# Import custom modules
from mochudimaps.locations.models import Location
from mochudimaps import settings


def index(request):
    'Display map'
    locations = Location.objects.order_by('name')
    return render_to_response('locations/index.html', {
    'locations': locations,
        'content': render_to_string('locations/locations.html', {'locations': locations}),
        }, context_instance=RequestContext(request))

Coulson Thabo Kgathi

unread,
Oct 24, 2012, 9:26:20 AM10/24/12
to django...@googlegroups.com
i used django template language to access value from my models in the database which are coordinates the using javascript i wrote a function that give a list of coordinates that are within a polygon in a map.

now i want to send that list back to a view or view then database table

thanks

Thomas Rega

unread,
Oct 24, 2012, 10:54:57 AM10/24/12
to django...@googlegroups.com, Coulson Thabo Kgathi
Am 24.10.12 11:26, schrieb Coulson Thabo Kgathi:
Hi,

like Stephen mentioned you can use a post request [1] for that.

The field 'data' could contain the list of coordinates in an array [2]
with the name 'coords' which itself can be accessed within the view via
request.POST['coords'].

One of many examples you can find here:
http://stackoverflow.com/questions/5457568/retrieving-post-data-from-jquery-in-django-without-a-form

[1] http://api.jquery.com/jQuery.post/
[2] http://de.selfhtml.org/javascript/objekte/array.htm

Good luck,

TR


> thanks
>
> --
> 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/-/Xf7F_Q9554YJ.
> 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.


--

Python Software Development - http://www.pyt3ch.com


Reply all
Reply to author
Forward
0 new messages