Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django: NoReverseMatch at / 'myapp' is not a registered namespace

I have this error during template rendering. What i'm trying to do is allow the user to upload a csv then process the data into models.

error at line 109 'myapp' is not a registered namespace

This is my line 109 code

<form action="{% url "myapp:upload_csv" %}" method="POST" enctype="multipart/form-data" class="form-horizontal"> 

urls.py in mysite

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'', include('anomaly.urls')),
]

urls.py in anomaly

urlpatterns = [
    url(r'^$', views.post_list, name='post_list'),
    url(r'^upload/csv/$', views.upload_csv, name='upload_csv'),
]
like image 708
Django newbie Avatar asked Jan 09 '18 05:01

Django newbie


2 Answers

try this
urls.py in mysite

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^', include('anomaly.urls',namespace='anomaly'))

To qualify a url name with a namespace use the syntax 'namespace:name'

<form action="{% url 'anomaly:upload_csv' %}" method="POST" enctype="multipart/form-data" class="form-horizontal"> 
like image 126
Baishakhi Dasgupta Avatar answered Sep 20 '22 18:09

Baishakhi Dasgupta


It seems that you have switched to Django 2.0 This is one of the change the new version of Django contains.
Go to urls.py of your app anomaly and add the app_name = "anomaly". So your urls.py file will be like

    app_name = "anomaly"

    urlpatterns = [
    url(r'^$', views.post_list, name='post_list'),
    url(r'^upload/csv/$', views.upload_csv, name='upload_csv'),
]
like image 36
Sam Avatar answered Sep 19 '22 18:09

Sam