0

EDIT 2: I know my url's for the views

url(r'^ngasite/', include('ngasite.urls')),
url(r'^admin/', admin.site.urls),
url(r'^', include('ngasite.urls')),

show an include twice, I thought i was basically switching the root over to be ngasite.urls etc, in either case as suggested this might be a problem I did remove this and it seemed to still fail with the no reverse match, and I am thinking its more of a parameter issue? Just wanted to update the issue with this.

EDIT: Posting urls.py for app and then for full django app:

from django.conf.urls import url
from . import views

app_name = 'ngasite'
urlpatterns = [
    # ex: /ngasite/
    url(r'^$', views.IndexView.as_view(), name='index'),
    # ex: /ngasite/5/
    url(r'^(?P<pk>[0-9]+)/$', views.DetailView.as_view(), name='detail'),
    # ex: /ngasite/5/results/
    url(r'^(?P<pk>[0-9]+)/results/$', views.ResultsView.as_view(), name='results'),
    # ex: /ngasite/5/vote/
    url(r'^(?P<question_id>[0-9]+)/vote/$', views.vote, name='vote'),

    url(r'^list/$', views.list, name='list'),
]

full app urls.py:

from django.conf.urls import url
from django.contrib import admin
from django.conf.urls import include
from django.views.generic import TemplateView

from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    url(r'^ngasite/', include('ngasite.urls')),
    url(r'^admin/', admin.site.urls),
    url(r'^', include('ngasite.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

I was trying to use the nice post someone made here for uploading files to django based website:

Need a minimal Django file upload example

did steps 1 thru 7 and everything seemed to run until i tried to hit my list url and I got an error in my list.html template view here:

<form action="{% url 'list' %}" method="post" enctype="multipart/form-data">

it complains about the url 'list' i believe, but I am not quite sure what the error is telling me. I admit I am a django newbie, and dove right into this example after getting a basic website up and running,thought I had the gist of Django guess not.

template file is the exact same in the example previous with the right appname change.

Full output Console output:

/usr/local/lib/python2.7/site-packages/django/shortcuts.py:45: RemovedInDjango110Warning: The context_instance argument of render_to_string is deprecated.
  using=using)

Internal Server Error: /ngasite/list/
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 149, in get_response
    response = self.process_exception_by_middleware(e, request)
  File "/usr/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 147, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/Users/shane.thomas/programming/fadeenv/ngasite/ngasite/views.py", line 77, in list
    context_instance=RequestContext(request)
  File "/usr/local/lib/python2.7/site-packages/django/shortcuts.py", line 45, in render_to_response
    using=using)
  File "/usr/local/lib/python2.7/site-packages/django/template/loader.py", line 114, in render_to_string
    template_name, context, context_instance, dirs, dictionary)
  File "/usr/local/lib/python2.7/site-packages/django/template/engine.py", line 244, in render_to_string
    return t.render(context_instance)
  File "/usr/local/lib/python2.7/site-packages/django/template/base.py", line 206, in render
    return self._render(context)
  File "/usr/local/lib/python2.7/site-packages/django/template/base.py", line 197, in _render
    return self.nodelist.render(context)
  File "/usr/local/lib/python2.7/site-packages/django/template/base.py", line 992, in render
    bit = node.render_annotated(context)
  File "/usr/local/lib/python2.7/site-packages/django/template/base.py", line 959, in render_annotated
    return self.render(context)
  File "/usr/local/lib/python2.7/site-packages/django/template/defaulttags.py", line 513, in render
    six.reraise(*exc_info)
  File "/usr/local/lib/python2.7/site-packages/django/template/defaulttags.py", line 499, in render
    url = reverse(view_name, args=args, kwargs=kwargs, current_app=current_app)
  File "/usr/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 600, in reverse
    return force_text(iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)))
  File "/usr/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 508, in _reverse_with_prefix
    (lookup_view_s, args, kwargs, len(patterns), patterns))
NoReverseMatch: Reverse for 'list' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
[02/May/2016 07:20:26] "GET /ngasite/list/ HTTP/1.1" 500 118169

Webpage output:

NoReverseMatch at /ngasite/list/
Reverse for 'list' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
Request Method:
GET
Request URL:
http://localhost:8000/ngasite/list/
Django Version:
1.9.5
Exception Type:
NoReverseMatch
Exception Value:
Reverse for 'list' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
Exception Location:
/usr/local/lib/python2.7/site-packages/django/core/urlresolvers.py in _reverse_with_prefix, line 508
Python Executable:
/usr/local/opt/python/bin/python2.7
Python Version:
2.7.11
Python Path:
['/Users/shane.thomas/programming/fadeenv/mysite',
 '/Library/Frameworks/SQLite3.framework/Versions/C/Python/2.7',
 '/Library/Frameworks/GEOS.framework/Versions/3/Python/2.7/site-packages',
 '/Library/Frameworks/GDAL.framework/Versions/1.11/Python/2.7/site-packages',
 '/usr/local/lib/python2.7/site-packages/pyproj-1.9.5.1-py2.7-macosx-10.11-x86_64.egg',
 '/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python27.zip',
 '/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
 '/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
 '/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
 '/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
 '/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
 '/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old',
 '/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload',
 '/usr/local/lib/python2.7/site-packages',
 '/usr/local/lib/python2.7/site-packages/geos',
 '/Library/Python/2.7/site-packages/numpy-override',
 '/Library/Python/2.7/site-packages']
Server time:
Mon, 2 May 2016 07:20:26 -0700
Error during template rendering
In template /Users/shane.thomas/programming/fadeenv/mysite/ngasite/templates/ngasite/list.html, error at line 20
Reverse for 'list' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
10
        <ul>

11
        {% for document in documents %}

12
            <li><a href="{{ document.docfile.url }}">{{ document.docfile.name }}</a></li>

13
        {% endfor %}

14
        </ul>

15
    {% else %}

16
        <p>No documents.</p>

17
    {% endif %}

18


19
        <!-- Upload form. Note enctype attribute! -->

20
        <form action="{% url 'list' %}" method="post" enctype="multipart/form-data">

21
            {% csrf_token %}

22
            <p>{{ form.non_field_errors }}</p>

F
Community
  • 1
  • 1
Codejoy
  • 3,722
  • 13
  • 59
  • 99

2 Answers2

0

I see some problem in your project url.py file

urlpatterns = [
    url(r'^ngasite/', include('ngasite.urls')),
    url(r'^admin/', admin.site.urls),
    url(r'^', include('ngasite.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

You have mentioned this twice

url(r'^ngasite/', include('ngasite.urls')),

url(r'^', include('ngasite.urls')),

This means there are two url paths for view.list

1) /list/
2) /ngasite/list/

I guess this must be the problem.Hope this helps

Amar
  • 666
  • 5
  • 13
  • actually I did that on purpose, cause I wanted the root of my.website.com to effectively go to the main app which is under my.website.com/ngasite I can take that secondary one out though to test and see but I am going to think this isn't the issue :( Update: did take out the secondary include url and it didn't change anything still same error. – Codejoy May 02 '16 at 18:26
0

I am answering my own question (I hate doing this) but maybe it will help another noob to django. The issue seemed like it was a namespacing issue, in my case I needed:

<form action="{% url 'ngasite:list' %}" method="post" enctype="multipart/form-data">

instead of the

<form action="{% url 'list' %}" method="post" enctype="multipart/form-data">

that I had

Codejoy
  • 3,722
  • 13
  • 59
  • 99