Reputation: 8162
I have created a simple app for file upload. Everything worked fine.Then I wanted to add simple login and now I have problems. These are my views
def login(request):
if request.method == 'POST':
form = LoginForm(request.POST)
if form.is_valid():
cd = form.cleaned_data
user = authenticate(username=cd['username'],password=cd['password'])
if user is not None:
if user is active:
login(request,user)
return HttpResponse('Authenticated successfully')
else:
return HttpResponse('Disabled account')
else:
return HttpResponse('Invalid login')
else:
form=LoginForm()
return render(request,'account/login.html',{'form': form})
def list(request):
# Handle file upload
if request.method == 'POST':
form = DocumentForm(request.POST, request.FILES)
if form.is_valid():
newdoc = Document(docfile=request.FILES['docfile'])
newdoc.save()
# Redirect to the document list after POST
return HttpResponseRedirect(reverse('list'))
else:
form = DocumentForm() # A empty, unbound form
# Load documents for the list page
documents = Document.objects.all()
# Render list page with the documents and the form
return render(request,'list.html',{'documents': documents, 'form': form})
This is fileupload/urls
from django.conf.urls import url
from fileupload.views import list
from fileupload.views import login
urlpatterns = [
url(r'^list/$', list, name='list'),
url(r'^login/$', login, name='login'),
]
My forms
class LoginForm(forms.Form):
username = forms.CharField()
password = forms.CharField(widget=forms.PasswordInput)
class DocumentForm(forms.Form):
docfile = forms.FileField(label='Select a file')
When I go to
http://127.0.0.1:8000/fileupload/list/
everything works fine.
If I try
http://127.0.0.1:8000/login/
I got this
I am confused becuase template is getting data from one fun and not from the other. How to debug this?
Upvotes: 0
Views: 27
Reputation: 26
It's clear that you and list and login in the URL should go after http://127.0.0.1:8000/fileupload/
Try check http://127.0.0.1:8000/fileupload/login/
Read this docs https://docs.djangoproject.com/en/1.11/topics/http/urls/
Upvotes: 1