Django Error : How to fix "App is not a registered namespace "


(PARTH JANI) #1

I used

Python 3.7
Django 2.0
My Project Name : fusion
My App Name : django_adminlte

I used all views and models file are in separated as files and folder.

I try to make task like user can upload csv or excel sheet in django app frontend side and usercan click on upload button then after uploaded excel sheet load in html tabel view at web page frontend side but i get below error,how to fixed it ?

I think some changes required in urls.py file but i alredy do it somthing but still get namaspace error

Error :

VIEWS FILE : load_csv.py

from django.shortcuts import render,redirect
from django.contrib.auth.decorators import login_required
import openpyxl


def load_csv(request):
    if "GET" == request.method:
        return render(request, 'load_csv.html', {})
    else:
        excel_file = request.FILES["excel_file"]
        wb = openpyxl.load_workbook(excel_file)
        sheets = wb.sheetnames
        print(sheets)

    worksheet = wb["Sheet1"]
    print(worksheet)

    active_sheet = wb.active
    print(active_sheet)

    print(worksheet["A1"].value)

    excel_data = list()
    for row in worksheet.iter_rows():
        row_data = list()
        for cell in row:
            row_data.append(str(cell.value))
            print(cell.value)
        excel_data.append(row_data)

    return render(request, 'load_csv.html', {"excel_data":excel_data})

URLS.PY file :

from django.conf.urls import url
from django.contrib import admin
from django.urls import path,include
from django_adminlte import views
from django.conf import settings
from django.conf.urls.static import static 
from django_adminlte.views.upload_csv import load_csv


urlpatterns = [
	path('admin/', admin.site.urls),

	path('load_csv/',views.upload_csv.load_csv,name='load_csv'),

	path('accounts/',include('django.contrib.auth.urls')),
]
if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL,document_root = settings.MEDIA_ROOT)

init.py File :

from .load_csv import*

HTML File :

{% extends 'adminlte/base.html' %}
{% load crispy_forms_tags %}
{% block content %}

<form action="{% url "django_adminlte:load_csv" %}" method="post" enctype="multipart/form-data">
	{% csrf_token %}
	<button type="submit" class="btn btn-primary">Upload File</button>
</form>
<br>
		{% for row in excel_data %}
            {% for cell in row %}
                {{ cell }}&nbsp;&nbsp;
            {% endfor %}
        {% endfor %}
        
{% endblock %}

(Basil Jose) #2

Either remove django_adminlte from your form action="{% url “django_adminlte:load_csv” %}", or include
django_adminlte apps with namespace in urls.py like url(r'^ltw/',include('django_adminlte.urls',namespace="django_adminlte"))


(PARTH JANI) #3

,how can i ignore this silly mistake , Thank you very much Basil now its excellent working,Again thanks


(Basil Jose) #4

Cool man!, we all make mistakes no one is perfect, but we should learn from our mistakes so that it wont’t comes up again.