Задать вопрос
@CteplerMarinovich

Не могу разобраться с django, как испортировать функцию?

Мой проект имеет такую структуру:
6408905593b3b443923809.png

И в папке women в файле views.py лежит отображения для страницы. Но я не могу добавить функцию index, которая выводит этот файл в файле urls.py в основном приложении? Я пытаюсь делать так:
from women.views import index1
from django.contrib import admin
from django.urls import path

urlpatterns = [
    path('admin/', admin.site.urls),
    path('women/', index1),  #http://127.0.0.1:8000/women/
]


Но получаю ошибку:
Exception in thread django-main-thread:
Traceback (most recent call last):
  File "C:\Users\стёпа\AppData\Local\Programs\Python\Python310\lib\threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "C:\Users\стёпа\AppData\Local\Programs\Python\Python310\lib\threading.py", line 953, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\стёпа\Desktop\SERVER\django\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
  File "C:\Users\стёпа\Desktop\SERVER\django\lib\site-packages\django\core\management\commands\runserver.py", line 134, in inner_run
    self.check(display_num_errors=True)
  File "C:\Users\стёпа\Desktop\SERVER\django\lib\site-packages\django\core\management\base.py", line 475, in check
    all_issues = checks.run_checks(
  File "C:\Users\стёпа\Desktop\SERVER\django\lib\site-packages\django\core\checks\registry.py", line 88, in run_checks
    new_errors = check(app_configs=app_configs, databases=databases)
  File "C:\Users\стёпа\Desktop\SERVER\django\lib\site-packages\django\core\checks\urls.py", line 14, in check_url_config
    return check_resolver(resolver)
  File "C:\Users\стёпа\Desktop\SERVER\django\lib\site-packages\django\core\checks\urls.py", line 24, in check_resolver
    return check_method()
  File "C:\Users\стёпа\Desktop\SERVER\django\lib\site-packages\django\urls\resolvers.py", line 494, in check
    for pattern in self.url_patterns:
  File "C:\Users\стёпа\Desktop\SERVER\django\lib\site-packages\django\utils\functional.py", line 57, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\Users\стёпа\Desktop\SERVER\django\lib\site-packages\django\urls\resolvers.py", line 715, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "C:\Users\стёпа\Desktop\SERVER\django\lib\site-packages\django\utils\functional.py", line 57, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\Users\стёпа\Desktop\SERVER\django\lib\site-packages\django\urls\resolvers.py", line 708, in urlconf_module
    return import_module(self.urlconf_name)
  File "C:\Users\стёпа\AppData\Local\Programs\Python\Python310\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "C:\Users\стёпа\Desktop\SERVER\coolsite\coolsite\urls.py", line 16, in <module>
    from women.views import index
ImportError: cannot import name 'index' from 'women.views' (C:\Users\стёпа\Desktop\SERVER\coolsite\women\views.py)
C:\Users\стёпа\Desktop\SERVER\coolsite\coolsite\urls.py changed, reloading.
Watching for file changes with StatReloader
Performing system checks...

Exception in thread django-main-thread:
Traceback (most recent call last):
  File "C:\Users\стёпа\AppData\Local\Programs\Python\Python310\lib\threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "C:\Users\стёпа\AppData\Local\Programs\Python\Python310\lib\threading.py", line 953, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\стёпа\Desktop\SERVER\django\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
  File "C:\Users\стёпа\Desktop\SERVER\django\lib\site-packages\django\core\management\commands\runserver.py", line 134, in inner_run
    self.check(display_num_errors=True)
  File "C:\Users\стёпа\Desktop\SERVER\django\lib\site-packages\django\core\management\base.py", line 475, in check
    all_issues = checks.run_checks(
  File "C:\Users\стёпа\Desktop\SERVER\django\lib\site-packages\django\core\checks\registry.py", line 88, in run_checks
    new_errors = check(app_configs=app_configs, databases=databases)
  File "C:\Users\стёпа\Desktop\SERVER\django\lib\site-packages\django\core\checks\urls.py", line 14, in check_url_config
    return check_resolver(resolver)
  File "C:\Users\стёпа\Desktop\SERVER\django\lib\site-packages\django\core\checks\urls.py", line 24, in check_resolver
    return check_method()
  File "C:\Users\стёпа\Desktop\SERVER\django\lib\site-packages\django\urls\resolvers.py", line 494, in check
    for pattern in self.url_patterns:
  File "C:\Users\стёпа\Desktop\SERVER\django\lib\site-packages\django\utils\functional.py", line 57, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\Users\стёпа\Desktop\SERVER\django\lib\site-packages\django\urls\resolvers.py", line 715, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "C:\Users\стёпа\Desktop\SERVER\django\lib\site-packages\django\utils\functional.py", line 57, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\Users\стёпа\Desktop\SERVER\django\lib\site-packages\django\urls\resolvers.py", line 708, in urlconf_module
    return import_module(self.urlconf_name)
  File "C:\Users\стёпа\AppData\Local\Programs\Python\Python310\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "C:\Users\стёпа\Desktop\SERVER\coolsite\coolsite\urls.py", line 16, in <module>
    from coolsite.women.views import index1
ModuleNotFoundError: No module named 'coolsite.women'
C:\Users\стёпа\Desktop\SERVER\coolsite\coolsite\urls.py changed, reloading.
Watching for file changes with StatReloader
Performing system checks...

Exception in thread django-main-thread:
Traceback (most recent call last):
  File "C:\Users\стёпа\AppData\Local\Programs\Python\Python310\lib\threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "C:\Users\стёпа\AppData\Local\Programs\Python\Python310\lib\threading.py", line 953, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\стёпа\Desktop\SERVER\django\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
  File "C:\Users\стёпа\Desktop\SERVER\django\lib\site-packages\django\core\management\commands\runserver.py", line 134, in inner_run
    self.check(display_num_errors=True)
  File "C:\Users\стёпа\Desktop\SERVER\django\lib\site-packages\django\core\management\base.py", line 475, in check
    all_issues = checks.run_checks(
  File "C:\Users\стёпа\Desktop\SERVER\django\lib\site-packages\django\core\checks\registry.py", line 88, in run_checks
    new_errors = check(app_configs=app_configs, databases=databases)
  File "C:\Users\стёпа\Desktop\SERVER\django\lib\site-packages\django\core\checks\urls.py", line 14, in check_url_config
    return check_resolver(resolver)
  File "C:\Users\стёпа\Desktop\SERVER\django\lib\site-packages\django\core\checks\urls.py", line 24, in check_resolver
    return check_method()
  File "C:\Users\стёпа\Desktop\SERVER\django\lib\site-packages\django\urls\resolvers.py", line 494, in check
    for pattern in self.url_patterns:
  File "C:\Users\стёпа\Desktop\SERVER\django\lib\site-packages\django\utils\functional.py", line 57, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\Users\стёпа\Desktop\SERVER\django\lib\site-packages\django\urls\resolvers.py", line 715, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "C:\Users\стёпа\Desktop\SERVER\django\lib\site-packages\django\utils\functional.py", line 57, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\Users\стёпа\Desktop\SERVER\django\lib\site-packages\django\urls\resolvers.py", line 708, in urlconf_module
    return import_module(self.urlconf_name)
  File "C:\Users\стёпа\AppData\Local\Programs\Python\Python310\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "C:\Users\стёпа\Desktop\SERVER\coolsite\coolsite\urls.py", line 16, in <module>
    from women.views import index1
ImportError: cannot import name 'index1' from 'women.views' (C:\Users\стёпа\Desktop\SERVER\coolsite\women\views.py)


Как это фиксить ?
  • Вопрос задан
  • 150 просмотров
Подписаться 1 Простой 10 комментариев
Пригласить эксперта
Ответы на вопрос 1
@begzad
Python developer and Backend(Django) developer
Можете показать сам views?
Ответ написан
Комментировать
Ваш ответ на вопрос

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

Похожие вопросы