Renita
window.location.replace("/")
Renita
like this?
Renita
inchidi
put that in calendar_entry.html line 28 inside your ajax success handler
Mahesh
Ok
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*
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
Renita
inchidi
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)
inchidi
Renita
yeah idk how
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
Renita
u mean: /calendar/entry/delete
Renita
not working :(
Renita
no
Renita
not working
Renita
same
inchidi
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);
}
inchidi
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]
inchidi
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]
inchidi
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
inchidi
btw since its already too long and its not more about django, can you pm me instead?
Renita
yes thanks
Mirco
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
None
I need to know which search engine came request from
None
how can I get it?
Rajjix
Rajjix
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
Mr. Rude
And what do you want to do with those values? Just display them?
Guilherme
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.
Mr. Rude