ValueError: строка исходного кода не может содержать нулевые байты в Django - PullRequest
0 голосов
/ 26 апреля 2020

Сейчас я изучаю django framework и застрял на следующей проблеме. Вот сообщение об ошибке

    Exception ignored in thread started by: <function check_errors.<locals>.wrapper at 0x044BF148>
Traceback (most recent call last):
  File "C:\Users\nodvo\.virtualenvs\web-e0x1-Fid\lib\site-packages\django\utils\autoreload.py", line 225, in wrapper   
    fn(*args, **kwargs)
  File "C:\Users\nodvo\.virtualenvs\web-e0x1-Fid\lib\site-packages\django\core\management\commands\runserver.py", line 
117, in inner_run
    self.check(display_num_errors=True)
  File "C:\Users\nodvo\.virtualenvs\web-e0x1-Fid\lib\site-packages\django\core\management\base.py", line 376, in check
    all_issues = self._run_checks(
  File "C:\Users\nodvo\.virtualenvs\web-e0x1-Fid\lib\site-packages\django\core\management\base.py", line 366, in _run_checks
    return checks.run_checks(**kwargs)
  File "C:\Users\nodvo\.virtualenvs\web-e0x1-Fid\lib\site-packages\django\core\checks\registry.py", line 71, in run_checks
    new_errors = check(app_configs=app_configs)
  File "C:\Users\nodvo\.virtualenvs\web-e0x1-Fid\lib\site-packages\django\core\checks\urls.py", line 40, in check_url_namespaces_unique
    all_namespaces = _load_all_namespaces(resolver)
  File "C:\Users\nodvo\.virtualenvs\web-e0x1-Fid\lib\site-packages\django\core\checks\urls.py", line 57, in _load_all_namespaces
    url_patterns = getattr(resolver, 'url_patterns', [])
  File "C:\Users\nodvo\.virtualenvs\web-e0x1-Fid\lib\site-packages\django\utils\functional.py", line 37, in __get__    
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\Users\nodvo\.virtualenvs\web-e0x1-Fid\lib\site-packages\django\urls\resolvers.py", line 533, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "C:\Users\nodvo\.virtualenvs\web-e0x1-Fid\lib\site-packages\django\utils\functional.py", line 37, in __get__    
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\Users\nodvo\.virtualenvs\web-e0x1-Fid\lib\site-packages\django\urls\resolvers.py", line 526, in urlconf_module
    return import_module(self.urlconf_name)
  File "C:\Users\nodvo\.virtualenvs\web-e0x1-Fid\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "E:\web_projects\pages\pages_project\urls.py", line 21, in <module>
    path('', include('pages.urls')),
  File "C:\Users\nodvo\.virtualenvs\web-e0x1-Fid\lib\site-packages\django\urls\conf.py", line 34, in include
    urlconf_module = import_module(urlconf_module)
  File "C:\Users\nodvo\.virtualenvs\web-e0x1-Fid\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 779, in exec_module
  File "<frozen importlib._bootstrap_external>", line 916, in get_code
  File "<frozen importlib._bootstrap_external>", line 846, in source_to_code
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
ValueError: source code string cannot contain null bytes

Я создал приложение под названием pages, затем добавил это приложение в settings.py как pages.apps.PagesConfig Я пытался изменить формат файла models.py на UTF-8 , но у меня не получилось.

Это pages.urls файл

from django.urls import path

from .views import HomePageView

urlpatterns = [
    path('', HomePageView.as_view(), name='home'), ]

это файл views.py

from django.views.generic import TemplateView


class HomePageView(TemplateView):
    template_name = 'home.html'

Это другой файл urls.py.

from django.contrib import admin
from django.urls import path, include

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