@SupV1rus
начинающий программист

ImportError at / main doesn't look like a module path как исправить?

Я в общем то начинающий, поэтому не судите так строго. Итак, я столкнулся с такой проблемой:

ImportError at /
main doesn't look like a module path
Request Method:	GET
Request URL:	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Django Version:	4.1.6
Exception Type:	ImportError
Exception Value:	
main doesn't look like a module path
Exception Location:	C:\Users\supik\AppData\Local\Programs\Python\Python310\lib\site-packages\django\utils\module_loading.py, line 27, in import_string
Raised during:	proj1.views.physic
Python Executable:	C:\Users\supik\AppData\Local\Programs\Python\Python310\python.exe
Python Version:	3.10.7
Python Path:	
['C:\\Users\\supik\\OneDrive\\Рабочий стол\\schoolproj\\proj1',
 'C:\\Users\\supik\\AppData\\Local\\Programs\\Python\\Python310\\python310.zip',
 'C:\\Users\\supik\\AppData\\Local\\Programs\\Python\\Python310\\DLLs',
 'C:\\Users\\supik\\AppData\\Local\\Programs\\Python\\Python310\\lib',
 'C:\\Users\\supik\\AppData\\Local\\Programs\\Python\\Python310',
 'C:\\Users\\supik\\AppData\\Roaming\\Python\\Python310\\site-packages',
 'C:\\Users\\supik\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages']
Server time:	Wed, 08 Feb 2023 09:41:21 +0000

Вот такая проблема, файлы:
views.py:
from django.shortcuts import render 
from .models import tabl, mol, el, opt


def physic(request):
    tabls = tabl.objects.all()
    return render(request, "main/physic.html", {"title:": "Мехника", "tabls": tabls})

def physic2(request):
    mols = mol.objects.all()
    return render(request, "main/physic2.html", {"mole:": "Молекулярная физика и термодинамика", "mols": mols})


def physic4(request):
    els = el.objects.all()
    return render(request, "main/physic4.html", {"el": "Электростатика и электродинамика", "els": els})
    
def physic3(request):
    opts = opt.objects.all()
    return render(request, "main/physic3.html", {"opt:": "Оптика, квантовая и атомная физика, СТО", "opts": opts})


setting.py:
"""
Django settings for proj1 project.

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

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

For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.1/ref/settings/
"""

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/4.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'

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

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'proj1',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'main',
]

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 = 'proj1.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        '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',
                'main',
            ],
        },
    },
]

WSGI_APPLICATION = 'proj1.wsgi.application'


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

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


# Password validation
# https://docs.djangoproject.com/en/4.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/4.1/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True


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

STATIC_URL = 'static/'

# Default primary key field type
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'


models.py:
from django.db import models

class tabl(models.Model):
    title = models.CharField("Название", max_length=50)
    tabl = models.TextField("Описание")
    
    def __str__(self):
        return self.title

    
    class Meta:
        verbose_name = "Механика"
        verbose_name_plural = "Механика"

class mol(models.Model):
    mole = models.CharField("Название", max_length=50)
    mol = models.TextField("Описание")
    
    def __str__(self):
        return self.mole

    
    class Meta:
        verbose_name = "Молекулярная физика"
        verbose_name_plural = "Молекулярная физика"


class el(models.Model):
    ele = models.CharField("Название", max_length=50)
    el = models.TextField("Описание")
    
    def __str__(self):  
        return self.ele

    
    class Meta:
        verbose_name = "Электричество"
        verbose_name_plural = "Электричество"


class opt(models.Model):
    opte = models.CharField("Название", max_length=50)
    opt = models.TextField("Описание")
    
    def __str__(self):
        return self.opte

    
    class Meta:
        verbose_name = "Оптика"
        verbose_name_plural = "Оптика"


и думаю, что понадобится urls.py
from django.urls import path
from . import views

urlpatterns = [
    path('', views.physic, name = 'p1'),
    path('physic2', views.physic2, name = 'p2'),
    path('physic4', views.physic4, name = 'p4'),
    path('physic3', views.physic3, name = 'p3'),
]


admin.py
from django.contrib import admin
from .models import el, opt, mol, tabl

admin.site.register(el)
admin.site.register(opt)
admin.site.register(mol)
admin.site.register(tabl)
  • Вопрос задан
  • 192 просмотра
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы