I have a project called django_swing. Within this project i have 2 different app. One is interface and the other is users. Within the django_swing folder for urls.py, I have the following:
path('login/', auth_views.LoginView.as_view(template_name='users/login.html'), name='login'),
Within login.html, I have the following:
<form action="#">
<div class="form-group">
<label for="username">Username</label>
<input class="form-control" type="text" id="username" required="" placeholder="Enter username">
</div>
<div class="form-group">
<a href="pages-recoverpw.html" class="text-muted float-right"><small>Forgot your password?</small></a>
<label for="password">Password</label>
<div class="input-group input-group-merge">
<input type="password" id="password" class="form-control" placeholder="Enter password">
<div class="input-group-append" data-password="false">
<div class="input-group-text">
<span class="password-eye"></span>
</div>
</div>
</div>
</div>
<div class="form-group mb-3">
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="checkbox-signin" checked>
<label class="custom-control-label" for="checkbox-signin">Remember me</label>
</div>
</div>
<div class="form-group mb-0 text-center">
<button class="btn btn-primary" type="submit"> Log In </button>
</div>
</form>
Within the interface folder for urls.py, I have the following:
path('', views.home, name='interface-home'),
Within the interface folder for views.py, I have the following:
def home(request):
return render(request, 'interface/home.html', {'title':'Home'} )
I have the file for home.html. As it is very long, I cant paste here. When i run the project, 127.0.0.1 loads the page for home.html.
Lastly, within the django_swing folder for settings.py, I have the following at the bottom of the file:
STATIC_URL = '/static/'
LOGIN_REDIRECT_URL='interface-home'
LOGIN_URL = 'login'
But when i access 127.0.0.1/login and key in with a account i just made followed by pressing the login button, the page refreshes with the same login page and the url becomes http://127.0.0.1:8000/login/?#. It is not jumping to interface-home as declared in settings.py. Can anyone advise me on how to solve this? I am a beginner at this. Thank you very much!
After editing the errors pointed out, i click login and got this the error of page not found for login/post
How come though?
CodePudding user response:
Your template has several issues
Your form method needs to be "post", the login view is expecting a POST request, and you shouldn't pass anything in the action attribute
<form method="post">
You also need to provide "name" parameters to your inputs so that their values are submitted with that name
<input id="username" name="username" ... >
<input id="password" name="password" ... >
