2017-12-15 2 views
0

Ich bin neu in Django und habe angefangen, meine erste Django App mit dem offiziellen Django Tutorial von https://docs.djangoproject.com/en/2.0/intro/tutorial01/ zu erstellen.ImportError: Kein Modul mit dem Namen 'posts.urls'

Ich habe python3.5.2 und pip 9.0.1 installiert, mit Ubuntu 16.04, Django Version 2.0.

meine urls.py Datei hat folgenden Code

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

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

Wenn es etwas ist, dass Sie mir diese Arbeit helfen kann. unten ist der Fehler i-Befehl nach dem Ausführen bin immer - Python manage.py runserver

hier wird der Fehler i

Performing system checks... 

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7fe20fe92d08> 
Traceback (most recent call last): 
    File "/usr/local/lib/python3.5/dist-packages/django/utils/autoreload.py", line 225, in wrapper 
    fn(*args, **kwargs) 
    File "/usr/local/lib/python3.5/dist-packages/django/core/management/commands/runserver.py", line 120, in inner_run 
    self.check(display_num_errors=True) 
    File "/usr/local/lib/python3.5/dist-packages/django/core/management/base.py", line 364, in check 
    include_deployment_checks=include_deployment_checks, 
    File "/usr/local/lib/python3.5/dist-packages/django/core/management/base.py", line 351, in _run_checks 
    return checks.run_checks(**kwargs) 
    File "/usr/local/lib/python3.5/dist-packages/django/core/checks/registry.py", line 73, in run_checks 
    new_errors = check(app_configs=app_configs) 
    File "/usr/local/lib/python3.5/dist-packages/django/core/checks/urls.py", line 40, in check_url_namespaces_unique 
    all_namespaces = _load_all_namespaces(resolver) 
    File "/usr/local/lib/python3.5/dist-packages/django/core/checks/urls.py", line 57, in _load_all_namespaces 
    url_patterns = getattr(resolver, 'url_patterns', []) 
    File "/usr/local/lib/python3.5/dist-packages/django/utils/functional.py", line 36, in __get__ 
    res = instance.__dict__[self.name] = self.func(instance) 
    File "/usr/local/lib/python3.5/dist-packages/django/urls/resolvers.py", line 536, in url_patterns 
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module) 
    File "/usr/local/lib/python3.5/dist-packages/django/utils/functional.py", line 36, in __get__ 
    res = instance.__dict__[self.name] = self.func(instance) 
    File "/usr/local/lib/python3.5/dist-packages/django/urls/resolvers.py", line 529, in urlconf_module 
    return import_module(self.urlconf_name) 
    File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module 
    return _bootstrap._gcd_import(name[level:], package, level) 
    File "<frozen importlib._bootstrap>", line 986, in _gcd_import 
    File "<frozen importlib._bootstrap>", line 969, in _find_and_load 
    File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked 
    File "<frozen importlib._bootstrap>", line 673, in _load_unlocked 
    File "<frozen importlib._bootstrap_external>", line 665, in exec_module 
    File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed 
    File "/var/www/html/django-projects/djangoblog/djangoblog/urls.py", line 21, in <module> 
    path('posts/', include('posts.urls')), 
    File "/usr/local/lib/python3.5/dist-packages/django/urls/conf.py", line 34, in include 
    urlconf_module = import_module(urlconf_module) 
    File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module 
    return _bootstrap._gcd_import(name[level:], package, level) 
    File "<frozen importlib._bootstrap>", line 986, in _gcd_import 
    File "<frozen importlib._bootstrap>", line 969, in _find_and_load 
    File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked 
ImportError: No module named 'posts.urls' 
Performing system checks... 

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7f8390058bf8> 
Traceback (most recent call last): 
    File "/usr/local/lib/python3.5/dist-packages/django/utils/autoreload.py", line 225, in wrapper 
    fn(*args, **kwargs) 
    File "/usr/local/lib/python3.5/dist-packages/django/core/management/commands/runserver.py", line 120, in inner_run 
    self.check(display_num_errors=True) 
    File "/usr/local/lib/python3.5/dist-packages/django/core/management/base.py", line 364, in check 
    include_deployment_checks=include_deployment_checks, 
    File "/usr/local/lib/python3.5/dist-packages/django/core/management/base.py", line 351, in _run_checks 
    return checks.run_checks(**kwargs) 
    File "/usr/local/lib/python3.5/dist-packages/django/core/checks/registry.py", line 73, in run_checks 
    new_errors = check(app_configs=app_configs) 
    File "/usr/local/lib/python3.5/dist-packages/django/core/checks/urls.py", line 40, in check_url_namespaces_unique 
    all_namespaces = _load_all_namespaces(resolver) 
    File "/usr/local/lib/python3.5/dist-packages/django/core/checks/urls.py", line 57, in _load_all_namespaces 
    url_patterns = getattr(resolver, 'url_patterns', []) 
    File "/usr/local/lib/python3.5/dist-packages/django/utils/functional.py", line 36, in __get__ 
    res = instance.__dict__[self.name] = self.func(instance) 
    File "/usr/local/lib/python3.5/dist-packages/django/urls/resolvers.py", line 536, in url_patterns 
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module) 
    File "/usr/local/lib/python3.5/dist-packages/django/utils/functional.py", line 36, in __get__ 
    res = instance.__dict__[self.name] = self.func(instance) 
    File "/usr/local/lib/python3.5/dist-packages/django/urls/resolvers.py", line 529, in urlconf_module 
    return import_module(self.urlconf_name) 
    File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module 
    return _bootstrap._gcd_import(name[level:], package, level) 
    File "<frozen importlib._bootstrap>", line 986, in _gcd_import 
    File "<frozen importlib._bootstrap>", line 969, in _find_and_load 
    File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked 
    File "<frozen importlib._bootstrap>", line 673, in _load_unlocked 
    File "<frozen importlib._bootstrap_external>", line 665, in exec_module 
    File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed 
    File "/var/www/html/django-projects/djangoblog/djangoblog/urls.py", line 21, in <module> 
    path('posts/', include('posts.urls')), 
    File "/usr/local/lib/python3.5/dist-packages/django/urls/conf.py", line 34, in include 
    urlconf_module = import_module(urlconf_module) 
    File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module 
    return _bootstrap._gcd_import(name[level:], package, level) 
    File "<frozen importlib._bootstrap>", line 986, in _gcd_import 
    File "<frozen importlib._bootstrap>", line 969, in _find_and_load 
    File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked 

bin immer, wenn es etwas ist, dass Sie mit mir helfen kann. Ich habe bereits jede andere im Internet existierende Lösung ausprobiert.

+0

Haben Sie eine Datei namens '__init __. Py' im Stammverzeichnis des Verzeichnisses' posts'? Um ein Verzeichnis zu einem Python-Modul zu machen, benötigen Sie die Datei '__init __. Py'. – MarkyPython

+0

Ja ich habe einen Dateinamen __init__.py im Stamm der Beiträge – Abhimanu

+1

Die grundlegenden Sachen müssen gefragt werden, haben Sie sicher eine 'urls.py' Datei in Ihrer Posts App? Kann kein Tippfehler sein, zum Beispiel "Post" statt "Posts"? –

Antwort

0

/var/www/html/django-projects/djangoblog/muss Ihr Projekt root sein. Wenn Sie ein IDE wie PyCharm verwenden, klicken Sie rechts auf die "djangoblog" -Ordner -> Mark Directory als -> Source Root

Wenn Sie eine Shell verwenden Django auszuführen:

cd /var/www/html/django-projects/djangoblog/ 
./manage.py runserver 

Hoffen, dass diese Werke für dich.

Verwandte Themen