Answer the question
In order to leave comments, you need to log in
How to make analog of https://namechk.com/ with Django?
Hello!
Can you please tell me how to make asynchronous calls to without reloading the page, like on the site https://namechk.com/ using Django?
I would like my backend to check for a free nickname, and the page itself accessed this backend asynchronously and received a response.
It is not very clear how a multiple asynchronous call of free name checks is made, then this data is obtained and displayed? On the above site, you can see that for each of the checked services, the answer comes at a different time and after that it is immediately displayed (the square changes color).
If possible, I would like to understand how to build the architecture of such a site, preferably as much python and server work as possible, and as little JS as possible.
Answer the question
In order to leave comments, you need to log in
Something like this:
urlpatterns = [
path('check-username/', check_username, name='check_username'),
]
@require_GET
def check_username(request):
if 'name' not in request.GET:
return HttpResponseBadRequest()
return JsonResponse({'exists': User.objects.filter(username__iexact=request.GET['name']).exists()})
$('#id_name').change(function() {
$.getJSON('/check-username/', {'name': $(this).val()}, function(user) {
if(user.exists)
alert('Пользователь с таким именем уже зарегистрирован');
});
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question