Renita
window.location.replace("/")
Renita
like this?
inchidi
window.location.replace("/")
yeah you can do that if you want to redirect to / after it deleted
inchidi
put that in calendar_entry.html line 28 inside your ajax success handler
Mahesh
Ok
inchidi
but this will be in while file?
i mean line 28 here https://dpaste.de/8gHu#L28
Renita
yeah i got that and what were you saying about views.py delete function
Renita
Like how do i linke HttpResponse to js file
Renita
link*
inchidi
Like how do i linke HttpResponse to js file
in your views, return HttpResponse("Anything or nothing") instead HttpResponseRedirect
Renita
okay wait a sec
Renita
ill do it
Renita
and how do i call the JS function then?
Renita
because onclck of delete button im calling the url
inchidi
because onclck of delete button im calling the url
revert the button like your old code. they will do same thing anyway. just with different behaviour
Renita
calendar.js:23 Uncaught ReferenceError: settings is not defined at deleteCalendarEntry (calendar.js:23) at HTMLButtonElement.onclick ((index):40) deleteCalendarEntry @ calendar.js:23 onclick @ (index):40 jquery.min.js:2 DELETE http://127.0.0.1:8000/calendar/entry/delete/undefined 404 (Not Found)
Renita
yeah idk how
inchidi
yeah idk how
how is your current views?
Renita
@login_required def delete(request, pk): if request.method == 'GET': entry = get_object_or_404(Entry, pk=pk) entry.delete() return HttpResponse(' ')
inchidi
oh i think i found the mistake
Renita
awesome
inchidi
in your calendar.js use full url instead /entry/delete
inchidi
or try remove the first /
Rajjix
did any of the admins participate in a pycon, or anything similar if yes point it out please 🤓
Renita
and ill change method to GET
Renita
in js
Renita
I removed /
Renita
but then too same error
inchidi
but then too same error
then try with full path
Renita
u mean: /calendar/entry/delete
Renita
not working :(
inchidi
u mean: /calendar/entry/delete
no, localhost:8000/entry/delete
Renita
no
Renita
not working
inchidi
not working
and the error?
Renita
same
inchidi
same
how is your js now?
Renita
function deleteCalendarEntry(entry){ var $entry = $(entry); $entry.parent().remove(); // var id = $entry.data('id'); var id = $(entry).data("id"); console.log("Hello!"); console.log(id); $.ajax({ url: 'localhost:8000/entry/delete' + id, method: 'DELETE', beforeSend: function(xhr){ xhr.setRequestHeader('X-CSRFToken', csrf_token); }, success: function (resp) { console.log("Successful"); window.location.replace("/"); }, error: function(e){ console.log('Error: '+e); }, }); console.log(settings.url); }
Renita
the error changed?
calendar.js:23 Uncaught ReferenceError: settings is not defined at deleteCalendarEntry (calendar.js:23) at HTMLButtonElement.onclick ((index):40) deleteCalendarEntry @ calendar.js:23 onclick @ (index):40 jquery.min.js:2 DELETE http://127.0.0.1:8000/calendar/entry/delete/undefined 404 (Not Found) send @ jquery.min.js:2 ajax @ jquery.min.js:2 deleteCalendarEntry @ calendar.js:10 onclick @ (index):40 calendar.js:20 Error: [object Object]
Renita
yes
Renita
see
Renita
Hello! calendar.js:9 undefined calendar.js:23 Uncaught ReferenceError: settings is not defined at deleteCalendarEntry (calendar.js:23) at HTMLButtonElement.onclick ((index):40) deleteCalendarEntry @ calendar.js:23 onclick @ (index):40 jquery.min.js:2 DELETE http://127.0.0.1:8000/calendar/entry/delete/undefined 404 (Not Found) send @ jquery.min.js:2 ajax @ jquery.min.js:2 deleteCalendarEntry @ calendar.js:10 onclick @ (index):40 calendar.js:20 Error: [object Object]
Renita
Hello! calendar.js:9 undefined calendar.js:23 Uncaught ReferenceError: settings is not defined at deleteCalendarEntry (calendar.js:23) at HTMLButtonElement.onclick ((index):40) deleteCalendarEntry @ calendar.js:23 onclick @ (index):40 jquery.min.js:2 DELETE http://127.0.0.1:8000/calendar/entry/delete/undefined 404 (Not Found) send @ jquery.min.js:2 ajax @ jquery.min.js:2 deleteCalendarEntry @ calendar.js:10 onclick @ (index):40 calendar.js:20 Error: [object Object]
Renita
function deleteCalendarEntry(entry){ var $entry = $(entry); $entry.parent().remove(); // var id = $entry.data('id'); var id = $(entry).data("id"); console.log("Hello!"); console.log(id); $.ajax({ //url: 'localhost:8000/entry/delete' + id, url: 'method', method: 'DELETE', beforeSend: function(xhr){ xhr.setRequestHeader('X-CSRFToken', csrf_token); }, success: function (resp) { console.log("Successful"); window.location.replace("/"); }, error: function(e){ console.log('Error: '+e); }, }); console.log(settings.url); }
inchidi
btw since its already too long and its not more about django, can you pm me instead?
Renita
yes thanks
Rajjix
I hope next year's PyCon Italy 🤞
Will be looking forward to see it Good luck 🍀
Rajjix
👍
George
How would you fit an argument into a modelform? @Inchidi class SelectFailureForm(forms.ModelForm): kind = forms.ChoiceField(choices=[(failure.pk,failure.kind) for failure in FailureType.objects.filter(spectrum='argument')]) class Meta: model = FailureType fields = ['kind','subject'] widgets = { 'kind': widgets.Select(attrs={'class': 'select'}), 'subject': widgets.Select(attrs={'class': 'select'}), }
George
I need just a thing to fit in my queryset
Mirco
Will be looking forward to see it Good luck 🍀
But not as speaker at the moment, I think I need more experience 💪
None
I need to know which search engine came request from
None
how can I get it?
Rajjix
I need to know which search engine came request from
This guy needs more experience in search engines
Rajjix
But most importantly we’ll get there
Rajjix
Hopefully
None
User agent
None
can get it from request.META['HTTP_USER_AGENT']
None
or <a href="{{ request.META.HTTP_REFERER }}">Referring Page</a>
Mr. Rude
And what do you want to do with those values? Just display them?
Guilherme
So how do you generate those values? And how often
I have a script that craw a specifc web page, then update the value of each key every 60 seconds.
Mr. Rude
I have a script that craw a specifc web page, then update the value of each key every 60 seconds.
So just to narrow down to specifics, you want to display these values in a div and want to update that div periodically?
Guilherme
So just to narrow down to specifics, you want to display these values in a div and want to update that div periodically?
Yes and I am already using AJAX to update the page with these values. But for now I am running the Script inside my View in every 60 seconds
Mr. Rude
Ajax is a way
Mr. Rude
But it could be costly to update every 60 secs
Guilherme
My script just run because I am calling it from my page.
Guilherme
But it could be costly to update every 60 secs
Yes, I agree. But this is just for a range time of the day.