Saturday, August 30, 2014

Re: how to call django web page with ordinary html page

If it helps, you can read/set the csrf cookie using javascript. here's some rough code:

  if(!document.cookie.match('csrftoken=([a-zA-Z0-9]{32})')){
   
for(var c = ''; c.length < 32;) c += Math.random().toString(36).substr(2, 1)
    document
.cookie = 'csrftoken=' + c + '; path=/'
 
}
  document
.write('<input type="hidden" name="csrfmiddlewaretoken" value="' + document.cookie.match('csrftoken=([a-zA-Z0-9]{32})')[1] + '">')

--
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/e696027d-09ef-4b6a-8e59-dc7c441020e3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Re: Django framework plugin

All you need to do is make sure the directory containing "Djangowork" is on the python path, then just add "Djangowork" to the INSTALLED_APPS of a different project.

see here for more info: https://docs.djangoproject.com/en/dev/intro/reusable-apps/

--
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/1647bb22-a5d5-44e8-b26b-477716b48dc8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Re: response to ajax (jquery) with variables

Hi again Antonio,

First of all, make sure you are using a good browser with debugging capabilities (I prefer Chrome), because you'll need it.

Secondly, I usually use the $.ajax request, instead of the post. Mainly because post is a wrapper around ajax and you can more finely change the settings of ajax.

So the post in your case would be:

$.ajax({
    type: 'POST',               // Make sure you post
    dataType: 'json',          // Use this so that you request json from the server
    url: "/sitioweb/json/",
    data: data,
    success: function(data) {
        // The data that is returned is your json data, already parser, so you don't have to parse it!
        alert(data.array[0]);     // Need to write "array" because that is what you are sending to the browser (your structure looks like that, check what the server is responding with)
    },
    error: function(xhr, textStatus, errorThrown) {
        console.log('AJAX communication failed:', textStatus, errorThrown);    // In case there is an error (for example a 500)
    }
});

Regards,

Andréas

2014-08-30 4:57 GMT+02:00 Antonio Russoniello <arussoni@musicparticles.com>:
Now I can read data from  ajax to my def but I have not idea to how send, for examle, an array to jquery and manage this from javascript...

I tried:

def json_prueba(request):
    arrg = [1,2,3,4]
    if request.method == 'POST':
        return HttpResponse(simplejson.dumps({'array': arrg}), content_type="application/json")
    return HttpResponse('FAIL!!!!!')

from the page side:

    function updateDB(){
        $.post("/sitioweb/json/", data, function(response){
            if(response){
                var data = JSON.parse(response); <--------- NOT SURE IF THIS IS CORRECT
                alert(data[0]); }              <----- I´m trying to put on an alert windows the first item of my array arrg
            else{ alert('Error! :(');}
        });
    }

Thanks in advande.

AR


El 28/08/2014 02:57 a.m., Andreas Kuhne escribió:
Hi Antonio,

import simplejson as json

return HttpResponse(
    json.dumps({
        'array': example
    }),
    content_type="application/json"
)

That would do the trick. This is returned as JSON. Remember to set the content_type, otherwise the client can get confused.

Regards,

Andréas

2014-08-28 2:56 GMT+02:00 Antonio Russoniello <arussoni@musicparticles.com>:
Hello,

i hope you can help me with this, I'm trying to send to an ajax (jquery from my html template) a response but i would like to send also a new variable.

in my html template I have:

    $("#init_date").click(function(){
        var some_date = {'init_date': init_date, 'end_date': end_date};
        $.post("/filter_dates/", some_date, function(response){
            if(response === 'success'){
                MAKE SOMETHING!!!
            else{ alert('error'); }
        });
    });

my django view look like:

def filter_date(request):
    if request.method == 'POST':
        example = ['A','B','C']
        init_date = request.POST['init_date']
        end_date = request.POST['end_date']
         MAKE SOMETHING!!
        return HttpResponse('success') AND HERE I WOULD LIKE TO SEND THE example ARRAY...
    else:
        return HttpResponse('error')

How can I send the array o some other variable as response?

Regards,
AR
--
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/53FE7E44.4020104%40musicparticles.com.
For more options, visit https://groups.google.com/d/optout.

--
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/CALXYUbnxRG8cs7_4-ALJUubXRPhx%2B2FQE1NA7bkTiBqoB1ySLw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

--
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/54013DA3.3090901%40musicparticles.com.

For more options, visit https://groups.google.com/d/optout.

--
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/CALXYUb%3DSeRDfD%3DTiGZKg7cYQ%3DMBrXxxG%2BJfFqp9At9cr%3D1CRgg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Friday, August 29, 2014

Re: how to call django web page with ordinary html page


On 30 Aug 2014 07:15, "James Schneider" <jrschneider83@gmail.com> wrote:
>
> I reread the OP, and it sounds like he is using a static HTML page served elsewhere and POSTing directly to the Django app. If you disable CSRF validation on the form view in Django, it should work. However, I would recommend against it.
>
> Unless you have a specific reason, why not just write up a quick TemplateView (with CSRF disabled on the FormView) or better yet a straight FormView class and just render the exact HTML you posted with the CSRF tag, taking advantage of the benefits that the Django framework offers?
>
> -James
>

This is exactly where i was going.
>
> On Friday, August 29, 2014, Pawan Soni <pawan.soni410@gmail.com> wrote:
>>
>>
>>
>> On Friday, August 29, 2014 5:47:19 PM UTC+5:30, Shubham Pansari wrote:
>>>
>>> You are missing csrf_token which is set by request for csrf verification. After the line
>>> <form action="http://127.0.0.1:8000/test/" method="post">
>>> in your code put {%csrf_token%} and it should work fine and also read why it didnot worked without it from https://docs.djangoproject.com/en/dev/ref/contrib/csrf/  . This should answer all your queries.
>>>
>>>
>>> On Fri, Aug 29, 2014 at 4:36 PM, Pawan Soni <pawan....@gmail.com> wrote:
>>>>
>>>> Hi ,
>>>>
>>>> i have a simple html page,p.html which is not made in django application ,its just a ordinary html page  which look like..
>>>>
>>>> <html>
>>>> <body>
>>>> <form action="http://127.0.0.1:8000/test/" method="post">
>>>> <input type="text" value="test" name="payemnt_ref">
>>>> <input type="submit">
>>>> </body>
>>>> <html>
>>>>
>>>> In form's action i am passing the path of my django url..
>>>>
>>>> this is my urls.py file..
>>>>
>>>>          from django.conf.urls import patterns, include, url
>>>>         from django.contrib import admin
>>>>         from login import views
>>>>               urlpatterns = patterns('',
>>>>            url(r'^test',views.paymentcheck_view,name="test"),
>>>>    )
>>>>
>>>> my views.py..
>>>>     
>>>>      def paymentcheck_view(request):
>>>>    if request.method == "POST":
>>>>         c = {}
>>>>         c.update(csrf(request))
>>>>         return render_to_response('login1/create_pay_page.html',c)
>>>>    else:
>>>>         return HttpResponse('GET')
>>>>
>>>> Error i got ...
>>>>
>>>> Forbidden (403)
>>>>
>>>> CSRF verification failed. Request aborted.
>>>>
>>>> ........
>>>>     
>>>> i am stuck over here,pls help me 
>>>>
>>>> Thnx in advance
>>>>
>>>>
>>>> ____________________________________________________________________
>>
>>              Thanks Shubham for guiding me and your precious response,but my concern is that if i used simple/plain html page and if i would use {%csrf_token %} in that page ,i think this is not working .

Did you actually try it?

>>               Is any other alternative ways to do this task.
>>     Thanks :)
>>
>>
>>   
>>>>
>>>> --
>>>> 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...@googlegroups.com.
>>>> To post to this group, send email to django...@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/2b21261b-c48f-43d2-8db0-810b0c7a9c02%40googlegroups.com.
>>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>>
>> --
>> 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/ed8d597a-5897-4be2-9402-f77d464700ff%40googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>
> --
> 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/CA%2Be%2BciX1SGsybHJvp%3DYhXR7gxYAKYdfGMw32ja3KsjzfVPF%3D9A%40mail.gmail.com.
>
> For more options, visit https://groups.google.com/d/optout.

--
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/CA%2BWjgXMcEbWFuyZqUuAsXF2Uw1mJ_u2ofLVqAO15H_Ba69PTHw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Re: how to call django web page with ordinary html page

I reread the OP, and it sounds like he is using a static HTML page served elsewhere and POSTing directly to the Django app. If you disable CSRF validation on the form view in Django, it should work. However, I would recommend against it.

Unless you have a specific reason, why not just write up a quick TemplateView (with CSRF disabled on the FormView) or better yet a straight FormView class and just render the exact HTML you posted with the CSRF tag, taking advantage of the benefits that the Django framework offers?

-James


On Friday, August 29, 2014, Pawan Soni <pawan.soni410@gmail.com> wrote:


On Friday, August 29, 2014 5:47:19 PM UTC+5:30, Shubham Pansari wrote:
You are missing csrf_token which is set by request for csrf verification. After the line
<form action="http://127.0.0.1:8000/test/" method="post">
in your code put {%csrf_token%} and it should work fine and also read why it didnot worked without it from https://docs.djangoproject.com/en/dev/ref/contrib/csrf/  . This should answer all your queries.


On Fri, Aug 29, 2014 at 4:36 PM, Pawan Soni <pawan....@gmail.com> wrote:
Hi ,

i have a simple html page,p.html which is not made in django application ,its just a ordinary html page  which look like..

<html>
<body>
<form action="http://127.0.0.1:8000/test/" method="post">
<input type="text" value="test" name="payemnt_ref">
<input type="submit">
</body>
<html>

In form's action i am passing the path of my django url..

this is my urls.py file..

         from django.conf.urls import patterns, include, url
        from django.contrib import admin
        from login import views
              urlpatterns = patterns('',
           url(r'^test',views.paymentcheck_view,name="test"),
   )

my views.py..
    
     def paymentcheck_view(request):
   if request.method == "POST":
        c = {}
        c.update(csrf(request))
        return render_to_response('login1/create_pay_page.html',c)
   else:
        return HttpResponse('GET')

Error i got ...

Forbidden (403)

CSRF verification failed. Request aborted.

........
    
i am stuck over here,pls help me 

Thnx in advance


____________________________________________________________________
             Thanks Shubham for guiding me and your precious response,but my concern is that if i used simple/plain html page and if i would use {%csrf_token %} in that page ,i think this is not working .
              Is any other alternative ways to do this task.
    Thanks :)


  

--
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...@googlegroups.com.
To post to this group, send email to django...@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/2b21261b-c48f-43d2-8db0-810b0c7a9c02%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
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/ed8d597a-5897-4be2-9402-f77d464700ff%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
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/CA%2Be%2BciX1SGsybHJvp%3DYhXR7gxYAKYdfGMw32ja3KsjzfVPF%3D9A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Re: how to call django web page with ordinary html page



On Friday, August 29, 2014 5:47:19 PM UTC+5:30, Shubham Pansari wrote:
You are missing csrf_token which is set by request for csrf verification. After the line
<form action="http://127.0.0.1:8000/test/" method="post">
in your code put {%csrf_token%} and it should work fine and also read why it didnot worked without it from https://docs.djangoproject.com/en/dev/ref/contrib/csrf/  . This should answer all your queries.


On Fri, Aug 29, 2014 at 4:36 PM, Pawan Soni <pawan....@gmail.com> wrote:
Hi ,

i have a simple html page,p.html which is not made in django application ,its just a ordinary html page  which look like..

<html>
<body>
<form action="http://127.0.0.1:8000/test/" method="post">
<input type="text" value="test" name="payemnt_ref">
<input type="submit">
</body>
<html>

In form's action i am passing the path of my django url..

this is my urls.py file..

         from django.conf.urls import patterns, include, url
        from django.contrib import admin
        from login import views
              urlpatterns = patterns('',
           url(r'^test',views.paymentcheck_view,name="test"),
   )

my views.py..
    
     def paymentcheck_view(request):
   if request.method == "POST":
        c = {}
        c.update(csrf(request))
        return render_to_response('login1/create_pay_page.html',c)
   else:
        return HttpResponse('GET')

Error i got ...

Forbidden (403)

CSRF verification failed. Request aborted.

........
    
i am stuck over here,pls help me 

Thnx in advance


____________________________________________________________________
             Thanks Shubham for guiding me and your precious response,but my concern is that if i used simple/plain html page and if i would use {%csrf_token %} in that page ,i think this is not working .
              Is any other alternative ways to do this task.
    Thanks :)


  

--
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...@googlegroups.com.
To post to this group, send email to django...@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/2b21261b-c48f-43d2-8db0-810b0c7a9c02%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
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/ed8d597a-5897-4be2-9402-f77d464700ff%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Re: related_query_name - what is it?

No problem.

I think I also found how to deal with M instances which are not related to R (R instances have foreign key to M). I tried M.filter(related_query_name_from_R__isnull=False) and it seems to work.

--
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/7881889c-c9df-4793-bfcb-7b488fbca7fc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.