Path('ajax/', views.validate_username, name = 'valid_usernmae'), ameError: name 'views' is not defined

from django.shortcuts import render
from django.views.generic import FormView
from .forms import JoinForm
from django.contrib.auth.forms import UserCreationForm
from django.views.generic.edit import CreateView
from django.http import JsonResponse

class SignUpView(CreateView):
template_name = ‘auth/signup.html’
form_class = UserCreationForm

def validate_username(request):
username = request.GET.get(‘username’, None)
data = {
return JsonResponse(data)

from django.urls import path
from . views import SignUpView,validate_username

urlpatterns = [
path(‘signup/’, SignUpView.as_view(), name = ‘signup’),
# path(‘ajax/validate_username/’, views.validate_username, name = valid_usernmae),
path(‘ajax/’, views.validate_username, name = ‘valid_usernmae’),

and template

{% extends 'base.html' %}

{% block javascript %}

{% endblock javascript %}

{% block content %}

{% csrf_token %}
<button type="submit" >SignUp</button>

{% endblock content %}

Error I am getting
File “”, line 219, in _call_with_fram
File “C:\Users\GNB\Desktop\development\django\love\myapp\”,
path(‘ajax/’, views.validate_username, name = ‘valid_usernmae’),
ameError: name ‘views’ is not defined

You imported the view as
from . views import SignUpView,validate_username

but you’re calling it this way:
path(‘ajax/’, views.validate_username, name = ‘valid_usernmae’),

change it to this:

path(‘ajax/’, validate_username, name = ‘valid_usernmae’),

1 Like

Thanks, brother ite works now.

1 Like