Click here to Skip to main content
14,865,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
ModuleNotFoundError: No module named 'dmapapp.forms'


I tried to resolve this error. But, my code is everything fine. But it shows a module not found an error.

settings.py
------------
"""
Django settings for dmappro project.

Generated by 'django-admin startproject' using Django 3.1.2.

For more information on this file, see
https://docs.djangoproject.com/en/3.1/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.1/ref/settings/
"""
import os
from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'ka574eal@^*#^4vlvb0gx4pk5t(7c--jghe%vkg^u-#c1&lfkr'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'dmapapp.apps.DmapappConfig',
    

]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'dmappro.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR,'templates')],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'dmappro.wsgi.application'


# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}


# Password validation
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/3.1/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/

STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR,'static')]



order_form.py
-----------
{% extends 'main.html' %}
{% load static %}
<!DOCTYPE html>
<html>
    <head>
        <title>Title</title>
    </head>
<body>
{% block content %}
<div class="row">
    <div class="col-md-6">
        <div class="card card-body">
            <form action="" method="POST">
                {% csrf_token %}
                {{form}}
                <input type="submit" name="Submit">
            </form>
        </div>
    </div>
</div>

{% endblock %}
</body>
</html>



urls.py
--------
from django.contrib import admin
from django.urls import path
from dmapapp import views

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', views.home, name='home'),
    path('products/', views.products, name='products'),
    path('customer/<pk>/', views.customer, name='customer'),
    path('create_order/', views.createorder, name='create_order')
]


views.py
---------
from django.shortcuts import render
from django.http import HttpResponse

# Create your views here.
from .models import *
from .forms import OrderForm

def home(request):
    orders = order.objects.all()
    customers = Customer.objects.all()


    total_customers = customers.count()

    total_orders = orders.count()
    delivered = orders.filter(status='Delivered').count()
    pending = orders.filter(status='Pending').count()

    context = { 'orders':orders, 'customers':customers, 'total_orders':total_orders, 'delivered':delivered, 'pending':pending }
    
    return render(request,'dashboard.html', context)

def products(request):
    products = product.objects.all()
     
    return render(request,'products.html', {'products': products})

def customer(request, pk):
    customer = Customer.objects.get(id=pk)

    orders = customer.order_set.all()
    order_count = orders.count()
    context = {'customer':customer, 'orders':orders, 'order_count':order_count}
    return render(request,'customer.html', context)

def createorder(request):
    form = OrderForm()
    context={'form':form}
    return render(request, 'order_form.html', context)



forms.py
--------
from django.forms import ModelForm 
from .models import order



class OrderForm(ModelForm):
    class Meta:
        model = order
        fields='__all__'


dashboard.html
--------------
{% extends 'main.html' %}
{% load static%}
<!DOCTYPE html>
<html>
    <head>
        <title>Title</title>
        {% include 'cdnlines.html' %}
        <link rel="stylesheet" type="text/css" href="{% static 'css/main.css' %}">
    </head>
<body>
{% block content %}
{% include 'status.html' %}
<br>
<div class="row">
<div class="col-md-5">
    <h5 class="font-weight-bold">Customers:</h5>
    <hr>
    <div class="card card-body">
        <a class="btn btn-primary btn-sm btn-block" href="">Create Customer:</a> 
        <table class="table table-sm">
            <tr>
                <th></th>
                <th>Customer</th>
                <th>Phone</th>
            </tr>

            {% for customer in customers %}
            <tr>
                <td><a href="{% url 'customer' customer.id %}" class="btn-sm btn-primary">View</a></td>
                <td>{{customer.name}}</td>
                <td>{{customer.phone}}</td>
            </tr>
            {% endfor %}
        </table>
    </div>
</div>

<div class="col-md-7">
    <h5>LAST 5 ORDERS:</h5>
    <hr>
    <div class="card card-body">
        <a class="btn btn-primary btn-sm btn-block" href="{% url 'create_order' %}">Create Order:</a>
        <table class="table table-sm">
            <tr>
                <th>Product</th>
                <th>Date Ordered</th>
                <th>Status</th>
                <th>Update</th>
                <th>Remove</th>
            </tr>

            {% for order in orders %}
            <tr>
                <td>{{order.product}}</td>
                <td>{{order.date_created}}</td>
                <td>{{order.status}}</td>
                <td><a href="" class="btn-sm btn-primary text-white">Update</a></td>
                <td><a href="" class="btn-sm btn-danger text-white">Delete</a></td>
            </tr>
            {% endfor %}
        </table>
    </div>
</div>
</div>
{% endblock %}
</body>
</html>


What I have tried:

<pre>ModuleNotFoundError: No module named 'dmapapp.forms'


I tried to resolve this error. But, my code is everything fine. But it shows a module not found an error.
Posted
Comments
Richard MacCutchan 10-Dec-20 11:47am
   
"But it shows a module not found an error."
Where?
Member 14122005 10-Dec-20 13:12pm
   
In views.py file in 6th line: from .forms import OrderForm

It shows this error:
ModuleNotFoundError: No module named 'dmapapp.forms'
Richard MacCutchan 11-Dec-20 5:53am
   
The problem is likely to be one of naming/location. The system is looking for a file named dmapapp.forms.py, but your project has it in a different place. Check your settings file to make sure the links are all correct.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900