Here is my urls.py
from django.conf.urls import include, url
from django.contrib import admin
from common.views import HomeView, LoadingSchoolView, ProcessSchoolView
urlpatterns = [
url(r'^$', HomeView.as_view(), name='Index'),
url(r'^admin/', include(admin.site.urls)),
url(r'^member/', include('member.urls', namespace='member')),
url(r'^common/', include('common.urls', namespace='common')),
In my common/urls.py
from django.conf.urls import url
from .views import QuerySchoolView
urlpatterns = {
url(r'^querySchool/(?P<q>[a-z]*)$', QuerySchoolView.as_view(), name='querySchool'),
}
Now, when I do
{% url 'common:querySchool' %},
It gives me a TypeError
TypeError at /member/register/learner
argument to reversed() must be a sequence
Request Method: GET
Request URL: http://127.0.0.1:8000/member/register/learner
Django Version: 1.8.2
Exception Type: TypeError
Exception Value:
argument to reversed() must be a sequence
Exception Location: /Users/enzii/python_env/django18/lib/python3.4/site-packages/django/core/urlresolvers.py in _populate, line 285
Python Executable: /Users/enzii/python_env/django18/bin/python3
Python Version: 3.4.3
Here is My View
class QuerySchoolView(View):
def get(self, request, q=""):
universities = University.objects.filter(Q(name__contains=q) |
Q(pinyin__contains=q) |
Q(province__contains=q) |
Q(country__contains=q))[:4]
returnObj = [{'unvis-name': u.name, 'country': u.country, 'province': u.province} for u in universities]
return HttpResponse(returnObj)
What is wrong with my {% url %}
?
You don't have a URL called "index", you have one called "Index".
And in your common/urls, you are using
{}
instead of[]
to wrap the patterns.In future, please post each question separately.