Re: How to get a variable from an ajax request and use it in another application in Django?

2021-12-04 Thread David Nugent
There's a little more to handling session data than what you have there
(unless code is missing?).

IIRC you need to set `session.modified = True` in order to persist the data.

Where are you serialising the session data? db, redis .. ?

Regards, David

On Fri, Dec 3, 2021 at 11:00 PM kayhan  wrote:

> Hi
> Sorry, as you said I used the session.
> But my problem has not been solved yet.
>
> I first send a request to Django and save its data with a session.
> I will send another request to Django later. Here I want to use the data
> of the previous request.
> But my code does not work properly. And the value "None" appears in the
> output.
> Thankful
>
> def planing(request): if request.is_ajax(): # Get user location from user
> location.js file: latitude = request.POST.get('latitude', None) longitude
> = request.POST.get('longitude', None) print("latitude, longitude = ",
> latitude,longitude) # To save data request.session['latitude'] = latitude
> request.session['longitude'] = longitude # To retrieve data: latitude =
> request.session.get('latitude') longitude = request.session.get(
> 'longitude') print("latitude, longitude = ", latitude,longitude) elif
> request.method == "GET": return render(request, "tourist/planing.html")
> elif request.method == "POST": # To retrieve data: latitude =
> request.session.get('latitude') longitude = request.session.get(
> 'longitude') print("latitude, longitude = ", latitude,longitude) Output:
> latitude, longitude = 34.801595 48.499574 latitude, longitude = 34.801595
> 48.499574 latitude, longitude = None None
>
> On Wed, Dec 1, 2021 at 6:37 PM kayhan  wrote:
>
>> Thank you David🙏🙏
>>
>> On Wed, Dec 1, 2021 at 3:56 AM David Nugent  wrote:
>>
>>> That is definitely much more clear.
>>>
>>> The usual way of doing this is to handle it like a shopping cart (plenty
>>> of examples only a google search away).
>>> Typically you store this information in the user's session in the first
>>> view, then retrieve it in the subsequent view(s).
>>>
>>> Note that `request.is_ajax` is deprecated and does not even exist
>>> anymore in Django 3.x. You can guess that from other info, but you should
>>> probably use a
>>> different view for handling the ajax request in any case, for clarity
>>> and maintainability. The response data would usually use a different format
>>> (json vs text/html).
>>>
>>> Regards, David
>>>
>>> On Wed, Dec 1, 2021 at 6:04 AM kayhan  wrote:
>>>
 Sorry I did not ask the question well.
 Question:
 How to first send some data with an Ajax request to Django view and
 then with a post request, send the form information to the same view and
 use the data sent in the previous request (Ajax request) in the second
 request ?

 def planing(request):

 if request.is_ajax():
 # Get user location from user location.js file:
 latitude = request.POST.get('latitude', None)
 longitude = request.POST.get('longitude', None)


 elif request.method == "GET":
 return render(request, "tourist/planing.html")


 elif request.method == "POST":
 # Here I want to take the form data and have
 #the previous request data (latitude, longitude) here and do a series
 of processing.

>>> --
>>> 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+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CAE5VhgWbiA8Ayhkss1saVg9my_S%2Bw8e1SYxhwp3xGCTD2L8snA%40mail.gmail.com
>>> 
>>> .
>>>
>> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAO-vjERuNQuJYLB6_67S_yV3AQhHaenoPWdAJwJ183GHYT2rGw%40mail.gmail.com
> 
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAE5VhgXiGgfahTnvoXxk31bM4SQPWj3bNas7G%2B9g%2BoAV-XouhA%40mail.gmail.com.


DateField and TimeField rendered as textfield in Django

2021-12-04 Thread Vishal Pandey
Hi everyone,
Whenever we use DateField and TimeField, django renders its html input 
field type as text.
I know it could be changed by customising the attributes in form class, but 
why is not by default.
I am also aware of the fact that date and time are supported by almost all 
browsers but not datetime-local.
Is it designed so?
If not, can I work upon this and make a PR in django's repository. ?

Thanks and Regards,
Vishal Pandey

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ae2a4ccb-a581-4371-972e-d9f59c375d50n%40googlegroups.com.


Re: static files not getting served

2021-12-04 Thread 'Mr. Aryan Sharma 4-Year B.Tech. Computer Science and Engineering' via Django users
At static files url at urls.py. And make a seperate directory for media
root as well.  Of your settings are correct project will get pushed .  Then
you ensure you have migrated from the console at heroku website

On Sat, 4 Dec, 2021, 8:55 pm Rahul,  wrote:

> hey guys  am using default database i.e. SQL Lite3 but when i deploy it on
> heroku my static files are not getting served . Please suggest what should
> i do??
>
> should i use postgres ???
>
> Please HELP
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/3afdbdd1-c481-498e-b659-44bfc2e691c4n%40googlegroups.com
> 
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAO10MeNkgFAGRfEyyNpH2ELzbZ9CE-F%3DTPoz9jRn1FVzE7zwUw%40mail.gmail.com.


Re: static files not getting served

2021-12-04 Thread Kasper Laudrup

On 04/12/2021 10.52, Rahul wrote:
hey guys  am using default database i.e. SQL Lite3 but when i deploy it 
on heroku my static files are not getting served . Please suggest what 
should i do??




You should tell us some relevant details, e.g. how you are deploying 
your project, any error messages, which instructions you have followed 
for deploying etc. so someone actually has a chance of helping you.




should i use postgres ???



Static files and the choice of database are not related so that won't 
make a difference.



Please HELP



Please don't SHOUT.

Kind regards,

Kasper Laudrup

--
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/525ad3b3-a502-1a1d-5b19-2c741e3cda38%40stacktrace.dk.


OpenPGP_0xE5D9CAC64AAA55EB.asc
Description: OpenPGP public key


OpenPGP_signature
Description: OpenPGP digital signature


static files not getting served

2021-12-04 Thread Rahul
hey guys  am using default database i.e. SQL Lite3 but when i deploy it on 
heroku my static files are not getting served . Please suggest what should 
i do??

should i use postgres ???

Please HELP

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3afdbdd1-c481-498e-b659-44bfc2e691c4n%40googlegroups.com.


Re: Get data from table rows and save in database

2021-12-04 Thread ram s
use name attribute in site input tag...

On Sat, Dec 4, 2021 at 3:47 PM Eugene TUYIZERE 
wrote:

> Dear Colleagues,
>
> I have data in the table. I want to get the rows value and save them in
> the database. How can I do this with jquery?
> The table I have is like this
> [image: image.png]
> This is what I have in HTML. The total is automatically calculated as I
> type the amount
>
> 
>  Description 
> Amount
> 
> 
> School Fess 
> 
> 
> 
> Restoration 
> 
> 
> 
> School materials 
> 
> 
>
> 
> TOTAL 
> 
> 
> 
> --
> *Eugene*
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CABxpZHsPPHbpkNOBDxGofAX-0uHPfGtgXYpHwoQo5iaqGOg9rg%40mail.gmail.com
> 
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAOGms29f25MTg3j4htoaJryt3GxpyneW6mUS4J%3Dww-hDRFR2Qg%40mail.gmail.com.


Re: Get data from table rows and save in database

2021-12-04 Thread Fredrick Ekoma
what is your product

On Sat, 4 Dec 2021, 11:17 am Eugene TUYIZERE, 
wrote:

> Dear Colleagues,
>
> I have data in the table. I want to get the rows value and save them in
> the database. How can I do this with jquery?
> The table I have is like this
> [image: image.png]
> This is what I have in HTML. The total is automatically calculated as I
> type the amount
>
> 
>  Description 
> Amount
> 
> 
> School Fess 
> 
> 
> 
> Restoration 
> 
> 
> 
> School materials 
> 
> 
>
> 
> TOTAL 
> 
> 
> 
> --
> *Eugene*
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CABxpZHsPPHbpkNOBDxGofAX-0uHPfGtgXYpHwoQo5iaqGOg9rg%40mail.gmail.com
> 
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAAobj6LJ_Wi-fLHT2zMAOg%2BhvQuMPDK2xyHpzhaHjjO3QS-E2A%40mail.gmail.com.


Re: Get data from table rows and save in database

2021-12-04 Thread Jet Ezra
STEPS
1. You will add a name attribute to all your input fields.
2. Add the crsf_token django template in-built filter to support 'POST'
3. Change your form's method to 'POST'
4. Add an action attribute and set it to your view
5. Then the JQUERY part will be as follows
6. Don't forget to give your form ad ID
Then
 $("#form_id").submit(function(e){
e.preventDefault()  //prevent the  default submit behaviour of a form
let data = $(this).serialize() // this picks all data basing on the name
attribute including the csrf_token
let URL = $(this).attr('action') //this pick the right URL like
http://localhostL:8000/add

//now perform the request
$.ajax({
url:url,
data:data,
type: "POST",
dataType: "json", // or the data type you expect from your response
beforeSend: function(){
// optional-> whatever you want to access before executing the request
// eg showing some loader
},
success: function(response){
// whatever you want to do on successful request
},
complete: () =>{
//whatever you want to do when  the request is complete
// stopping some loader
}

})
})




On Sat, Dec 4, 2021 at 1:17 PM Eugene TUYIZERE 
wrote:

> Dear Colleagues,
>
> I have data in the table. I want to get the rows value and save them in
> the database. How can I do this with jquery?
> The table I have is like this
> [image: image.png]
> This is what I have in HTML. The total is automatically calculated as I
> type the amount
>
> 
>  Description 
> Amount
> 
> 
> School Fess 
> 
> 
> 
> Restoration 
> 
> 
> 
> School materials 
> 
> 
>
> 
> TOTAL 
> 
> 
> 
> --
> *Eugene*
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CABxpZHsPPHbpkNOBDxGofAX-0uHPfGtgXYpHwoQo5iaqGOg9rg%40mail.gmail.com
> 
> .
>


-- 
jet

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAMjc0xUTy_CaWpkxuMrcjytXaLYHXBTWoSuLrdp4-bCLW1H4%3Dw%40mail.gmail.com.


Get data from table rows and save in database

2021-12-04 Thread Eugene TUYIZERE
Dear Colleagues,

I have data in the table. I want to get the rows value and save them in the
database. How can I do this with jquery?
The table I have is like this
[image: image.png]
This is what I have in HTML. The total is automatically calculated as I
type the amount


 Description 
Amount


School Fess 



Restoration 



School materials 




TOTAL 



-- 
*Eugene*

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CABxpZHsPPHbpkNOBDxGofAX-0uHPfGtgXYpHwoQo5iaqGOg9rg%40mail.gmail.com.


Re: Use previously requested data in another request

2021-12-04 Thread kayhan
Thankyou 🙏

On Sat, Dec 4, 2021 at 11:33 AM Lalit Suthar 
wrote:

> tried to look into the docs but couldn't find a reason.
> you can go through this page to find out any possible reason
> https://docs.djangoproject.com/en/dev/topics/http/sessions/
>
> On Fri, 3 Dec 2021 at 23:19, kayhan  wrote:
>
>> Thanks but I did not change the settings.
>> And to test, SESSION_COOKIE_AGE = 5 * 60,
>>   I added to the settings but there is still the same problem.
>>
>> On Fri, Dec 3, 2021 at 8:55 PM Lalit Suthar 
>> wrote:
>>
>>> We can save that in any django model in ajax() request if possible.
>>>
>>> You can check if you have modified `SESSION_COOKIE_AGE` (
>>> https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-SESSION_COOKIE_AGE
>>> )
>>> if it is too less that might be the reason.
>>>
>>> On Fri, 3 Dec 2021 at 16:15, kayhan  wrote:
>>>
 Hi
 I first send a request to Django and save its data with a session.
 I will send another request to Django later. Here I want to use the
 data of the previous request.
 But my code does not work properly. And the value "None" appears in the
 output.
 Does anyone know what I should do?
 Thankful

 def planing(request): if request.is_ajax(): # Get user location from
 user location.js file: latitude = request.POST.get('latitude', None)
 longitude = request.POST.get('longitude', None) print("latitude,
 longitude = ", latitude,longitude) # To save data request.session[
 'latitude'] = latitude request.session['longitude'] = longitude # To
 retrive data: latitude = request.session.get('latitude') longitude =
 request.session.get('longitude') print("latitude, longitude = ",
 latitude,longitude) elif request.method == "GET": return
 render(request, "tourist/planing.html") elif request.method == "POST": #
 To retrive data: latitude = request.session.get('latitude') longitude
 = request.session.get('longitude') print("latitude, longitude = ",
 latitude,longitude) Output: latitude, longitude = 34.801595 48.499574
 latitude, longitude = 34.801595 48.499574 latitude, longitude = None
 None

 --
 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+unsubscr...@googlegroups.com.
 To view this discussion on the web visit
 https://groups.google.com/d/msgid/django-users/4bef9d07-cd92-440a-8ec0-dd4c206e6ae7n%40googlegroups.com
 
 .

>>> --
>>> 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+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CAGp2JVEkLiwVEAF3uV%3DBBOQJuUwVBaQGhD7RA7t0aDirh%2BD-ZQ%40mail.gmail.com
>>> 
>>> .
>>>
>> --
>> 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+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAO-vjETOG1Nq%3D_Evk7ryvr27eBxtDSQfiygKV%3Djq9TTzkiuPTw%40mail.gmail.com
>> 
>> .
>>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAGp2JVE1byyT%2BO8Rxx%2BuGh49ouxvMs8MLmHHWzL-1c_WR8ssnw%40mail.gmail.com
> 
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAO-vjES24HDPNXmxZS6i5K%2BVYTO7W5rDQtZLsn%3DjnYy694XuHw%40mail.gmail.com.


Re: Use previously requested data in another request

2021-12-04 Thread Lalit Suthar
tried to look into the docs but couldn't find a reason.
you can go through this page to find out any possible reason
https://docs.djangoproject.com/en/dev/topics/http/sessions/

On Fri, 3 Dec 2021 at 23:19, kayhan  wrote:

> Thanks but I did not change the settings.
> And to test, SESSION_COOKIE_AGE = 5 * 60,
>   I added to the settings but there is still the same problem.
>
> On Fri, Dec 3, 2021 at 8:55 PM Lalit Suthar 
> wrote:
>
>> We can save that in any django model in ajax() request if possible.
>>
>> You can check if you have modified `SESSION_COOKIE_AGE` (
>> https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-SESSION_COOKIE_AGE
>> )
>> if it is too less that might be the reason.
>>
>> On Fri, 3 Dec 2021 at 16:15, kayhan  wrote:
>>
>>> Hi
>>> I first send a request to Django and save its data with a session.
>>> I will send another request to Django later. Here I want to use the data
>>> of the previous request.
>>> But my code does not work properly. And the value "None" appears in the
>>> output.
>>> Does anyone know what I should do?
>>> Thankful
>>>
>>> def planing(request): if request.is_ajax(): # Get user location from
>>> user location.js file: latitude = request.POST.get('latitude', None)
>>> longitude = request.POST.get('longitude', None) print("latitude,
>>> longitude = ", latitude,longitude) # To save data request.session[
>>> 'latitude'] = latitude request.session['longitude'] = longitude # To
>>> retrive data: latitude = request.session.get('latitude') longitude =
>>> request.session.get('longitude') print("latitude, longitude = ",
>>> latitude,longitude) elif request.method == "GET": return
>>> render(request, "tourist/planing.html") elif request.method == "POST": #
>>> To retrive data: latitude = request.session.get('latitude') longitude =
>>> request.session.get('longitude') print("latitude, longitude = ",
>>> latitude,longitude) Output: latitude, longitude = 34.801595 48.499574
>>> latitude, longitude = 34.801595 48.499574 latitude, longitude = None
>>> None
>>>
>>> --
>>> 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+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/4bef9d07-cd92-440a-8ec0-dd4c206e6ae7n%40googlegroups.com
>>> 
>>> .
>>>
>> --
>> 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+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAGp2JVEkLiwVEAF3uV%3DBBOQJuUwVBaQGhD7RA7t0aDirh%2BD-ZQ%40mail.gmail.com
>> 
>> .
>>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAO-vjETOG1Nq%3D_Evk7ryvr27eBxtDSQfiygKV%3Djq9TTzkiuPTw%40mail.gmail.com
> 
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAGp2JVE1byyT%2BO8Rxx%2BuGh49ouxvMs8MLmHHWzL-1c_WR8ssnw%40mail.gmail.com.