I am getting the following error inspite of including the url name in urls.py:
Reverse for 'upload' with arguments '()' and keyword arguments '{}' not found.0 pattern(s) tried: []
I have given the url name as 'upload' in urls.py initially home.html is supposed to post to 'upload' which is the FileView which i have included as:
url(r'^upload/',FileView.as_view(),name='upload')
views.py
def initial(request):
return render(request,'display/home.html')
class FileView(FormView):
template_name = 'display/upload.html'
form_class = FileForm
success_url = 'success/'
def form_valid(self, form):
file_upload = FileModel(
fileup=self.get_form_kwargs().get('files')['fileup'])
#results = FileForm.objects.filter(Q(name__icontains=your_search_query) | Q(startdate__icontains=your_search_query) | Q(enddate__icontains=your_search_query)).order_by('pub_date')
file_upload.save()
self.id = file_upload.id
return render_to_response('display/success.html')
return HttpResponseRedirect(self.get_success_url())
def get_success_url(self):
return reverse('file_upload', kwargs={'pk': self.id})
def redirect(request):
return render(request,"display/success.html")
...
urls.py
from django.conf.urls import url
from . import views
from display.views import FileView
urlpatterns = [
url(r'^start/', views.initial,name='home'),
url(r'^upload/',FileView.as_view(),name='upload'),
url(r'^success/',views.redirect,name='success'),
#url(r'^upload',views.upload,name='upload'),
]
templates home.html
<!DOCTYPE html>
<html>
<head>
<title>CSV FILE UPLOAD</title>
</head>
<body>
<form enctype="multipart/form-data" method="POST" action="{% url 'upload' %}">
{% csrf_token %}
<input type="submit" name="submit" />
</form>
</body>
This urls.py
doesn't look like a root url conf... maybe a include inside your root url conf is missing?
Example:
urlpatterns = [
url(r'^display/', include('display.urls', namespace='display')),
]
If it's included like this, you should refer to the upload
url as:
<form enctype="multipart/form-data" method="POST" action="{% url 'display:upload' %}">
Other possible solution, try adding $
in the end of your url regex:
from django.conf.urls import url
from . import views
from display.views import FileView
urlpatterns = [
url(r'^start/$', views.initial,name='home'),
url(r'^upload/$',FileView.as_view(),name='upload'),
url(r'^success/$',views.redirect,name='success'),
]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.