0

Трейсбек консоли:

Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
  File "C:\Python39\lib\threading.py", line 954, in _bootstrap_inner
    self.run()
  File "C:\Python39\lib\threading.py", line 892, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Python39\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
    fn(*args, **kwargs)
  File "C:\Python39\lib\site-packages\django\core\management\commands\runserver.py", line 110, in inner_run
    autoreload.raise_last_exception()
  File "C:\Python39\lib\site-packages\django\utils\autoreload.py", line 76, in raise_last_exception
    raise _exception[1]
  File "C:\Python39\lib\site-packages\django\core\management\__init__.py", line 357, in execute
    autoreload.check_errors(django.setup)()
  File "C:\Python39\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
    fn(*args, **kwargs)
  File "C:\Python39\lib\site-packages\django\__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "C:\Python39\lib\site-packages\django\apps\registry.py", line 91, in populate
    app_config = AppConfig.create(entry)
  File "C:\Python39\lib\site-packages\django\apps\config.py", line 90, in create
    module = import_module(entry)
  File "C:\Python39\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'bootstrap3'
Traceback (most recent call last):
  File "D:\Programming\Python\Python+Django_Udemy\Social_Clone_Project\simple_social_clone\simplesocial\manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Python39\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "C:\Python39\lib\site-packages\django\core\management\__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Python39\lib\site-packages\django\core\management\base.py", line 330, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Python39\lib\site-packages\django\core\management\commands\runserver.py", line 61, in execute
    super().execute(*args, **options)
  File "C:\Python39\lib\site-packages\django\core\management\base.py", line 371, in execute
    output = self.handle(*args, **options)
  File "C:\Python39\lib\site-packages\django\core\management\commands\runserver.py", line 96, in handle
    self.run(**options)
  File "C:\Python39\lib\site-packages\django\core\management\commands\runserver.py", line 103, in run
    autoreload.run_with_reloader(self.inner_run, **options)
  File "C:\Python39\lib\site-packages\django\utils\autoreload.py", line 618, in run_with_reloader
    start_django(reloader, main_func, *args, **kwargs)
  File "C:\Python39\lib\site-packages\django\utils\autoreload.py", line 603, in start_django
    reloader.run(django_main_thread)
  File "C:\Python39\lib\site-packages\django\utils\autoreload.py", line 318, in run
    self.run_loop()
  File "C:\Python39\lib\site-packages\django\utils\autoreload.py", line 324, in run_loop
    next(ticker)
  File "C:\Python39\lib\site-packages\django\utils\autoreload.py", line 364, in tick
    for filepath, mtime in self.snapshot_files():
  File "C:\Python39\lib\site-packages\django\utils\autoreload.py", line 380, in snapshot_files
    for file in self.watched_files():
  File "C:\Python39\lib\site-packages\django\utils\autoreload.py", line 278, in watched_files
    yield from iter_all_python_module_files()
  File "C:\Python39\lib\site-packages\django\utils\autoreload.py", line 105, in iter_all_python_module_files
    return iter_modules_and_files(modules, frozenset(_error_files))
  File "C:\Python39\lib\site-packages\django\utils\autoreload.py", line 141, in iter_modules_and_files
    resolved_path = path.resolve(strict=True).absolute()
  File "C:\Python39\lib\pathlib.py", line 1204, in resolve
    s = self._flavour.resolve(self, strict=strict)
  File "C:\Python39\lib\pathlib.py", line 200, in resolve
    return self._ext_to_normal(_getfinalpathname(s))
OSError: [WinError 123] Синтаксическая ошибка в имени файла, имени папки или метке тома: '<frozen importlib._bootstrap>'

manage.py

#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "simplesocial.settings")
    try:
        from django.core.management import execute_from_command_line
    except ImportError:
        # The above import may fail for some other reason. Ensure that the
        # issue is really that Django is missing to avoid masking other
        # exceptions on Python 2.
        try:
            import django
        except ImportError:
            raise ImportError(
                "Couldn't import Django. Are you sure it's installed and "
                "available on your PYTHONPATH environment variable? Did you "
                "forget to activate a virtual environment?"
            )
        raise
    execute_from_command_line(sys.argv)

views.py

    from django.contrib import messages
    from django.contrib.auth.mixins import LoginRequiredMixin
    
    from django.urls import reverse_lazy
    from django.http import Http404
    from django.views import generic
    
    from braces.views import SelectRelatedMixin
    
    from . import forms
    from . import models
    
    from django.contrib.auth import get_user_model
    User = get_user_model()
    
    
    class PostList(SelectRelatedMixin, generic.ListView):
        model = models.Post
        select_related = ("user", "group")
    
    
    class UserPosts(generic.ListView):
        model = models.Post
        template_name = "posts/user_post_list.html"
    
        def get_queryset(self):
            try:
                self.post_user = User.objects.prefetch_related("posts").get(
                    username__iexact=self.kwargs.get("username")
                )
            except User.DoesNotExist:
                raise Http404
            else:
                return self.post_user.posts.all()
    
        def get_context_data(self, **kwargs):
            context = super().get_context_data(**kwargs)
            context["post_user"] = self.post_user
            return context
    
    
    class PostDetail(SelectRelatedMixin, generic.DetailView):
        model = models.Post
        select_related = ("user", "group")
    
        def get_queryset(self):
            queryset = super().get_queryset()
            return queryset.filter(
                user__username__iexact=self.kwargs.get("username")
            )
    
    class CreatePost(LoginRequiredMixin, SelectRelatedMixin, 
    generic.CreateView):
        # form_class = forms.PostForm
        fields = ('message','group')
        model = models.Post
    
        # def get_form_kwargs(self):
        #     kwargs = super().get_form_kwargs()
        #     kwargs.update({"user": self.request.user})
        #     return kwargs
    
        def form_valid(self, form):
            self.object = form.save(commit=False)
            self.object.user = self.request.user
            self.object.save()
            return super().form_valid(form)
    
    
    class DeletePost(LoginRequiredMixin, SelectRelatedMixin, 
    generic.DeleteView):
        model = models.Post
        select_related = ("user", "group")
        success_url = reverse_lazy("posts:all")
    
        def get_queryset(self):
            queryset = super().get_queryset()
            return queryset.filter(user_id=self.request.user.id)
    
        def delete(self, *args, **kwargs):
            messages.success(self.request, "Post Deleted")
            return super().delete(*args, **kwargs)

                 
File"D:\Programming\Python\Python+Django_Udemy\Social_Clone_Project\simple_social_clone\simplesocial\posts\views.py", line 8, in <module>
    from braces.views import SelectRelatedMixin
ModuleNotFoundError: No module named 'braces'
4
  • 1
    ModuleNotFoundError: No module named 'bootstrap3' pip3 install django-bootstrap3 stackoverflow.com/a/29799343/12785139
    – kubada
    3 фев 2021 в 11:58
  • проверьте settings.INSTALLED_APPS, везде стоят запятые?
    – Jack_oS
    3 фев 2021 в 11:58
  • исправил, но возникла новая ошибка 3 фев 2021 в 13:38
  • сам все таки исправил 3 фев 2021 в 16:05

1 ответ 1

0

У меня возникала такая проблема пару раз. Решал ее просто - переустанавливал все зависимости.

Создаём файл со всеми зависимостями: pip freeze -r requirments.txt

Удаляем все зависимости: pip uninstall -r requirments.txt

Ставим заново: pip install -r requirments.txt

Незабываем, что у меня всё в виртуальном окружении находится. Также предполагаю, что просто переустановки django хватило бы, но я не проверял.

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.