2017-03-14 62 views
-2

我正在使用Visual Studio 2013和Python工具爲VS 2013開始使用Django網站。無法導入名稱視圖 - django

Related question: cannot import name patterns - django

我已經解決了這個問題,現在我收到以下錯誤,

enter image description here

全部追溯,

Performing system checks... 

Traceback (most recent call last): 
    File "C:\Users\my_username\documents\visual studio 2013\Projects\DjangoWebProject1\DjangoWebProject1\manage.py", line 17, in <module> 
    execute_from_command_line(sys.argv) 
    File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 367, in execute_from_command_line 
    utility.execute() 
    File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 359, in execute 
    self.fetch_command(subcommand).run_from_argv(self.argv) 
    File "C:\Python27\lib\site-packages\django\core\management\base.py", line 294, in run_from_argv 
    self.execute(*args, **cmd_options) 
    File "C:\Python27\lib\site-packages\django\core\management\commands\runserver.py", line 58, in execute 
    super(Command, self).execute(*args, **options) 
    File "C:\Python27\lib\site-packages\django\core\management\base.py", line 345, in execute 
    output = self.handle(*args, **options) 
    File "C:\Python27\lib\site-packages\django\core\management\commands\runserver.py", line 97, in handle 
    self.run(**options) 
    File "C:\Python27\lib\site-packages\django\core\management\commands\runserver.py", line 108, in run 
    self.inner_run(None, **options) 
    File "C:\Python27\lib\site-packages\django\core\management\commands\runserver.py", line 121, in inner_run 
    self.check(display_num_errors=True) 
    File "C:\Python27\lib\site-packages\django\core\management\base.py", line 374, in check 
    include_deployment_checks=include_deployment_checks, 
    File "C:\Python27\lib\site-packages\django\core\management\base.py", line 361, in _run_checks 
    return checks.run_checks(**kwargs) 
    File "C:\Python27\lib\site-packages\django\core\checks\registry.py", line 81, in run_checks 
    new_errors = check(app_configs=app_configs) 
    File "C:\Python27\lib\site-packages\django\core\checks\urls.py", line 14, in check_url_config 
    return check_resolver(resolver) 
    File "C:\Python27\lib\site-packages\django\core\checks\urls.py", line 24, in check_resolver 
    for pattern in resolver.url_patterns: 
    File "C:\Python27\lib\site-packages\django\utils\functional.py", line 35, in __get__ 
    res = instance.__dict__[self.name] = self.func(instance) 
    File "C:\Python27\lib\site-packages\django\urls\resolvers.py", line 313, in url_patterns 
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module) 
    File "C:\Python27\lib\site-packages\django\utils\functional.py", line 35, in __get__ 
    res = instance.__dict__[self.name] = self.func(instance) 
    File "C:\Python27\lib\site-packages\django\urls\resolvers.py", line 306, in urlconf_module 
    return import_module(self.urlconf_name) 
    File "C:\Python27\lib\importlib\__init__.py", line 37, in import_module 
    __import__(name) 
    File "C:\Users\my_username\documents\visual studio 2013\Projects\DjangoWebProject1\DjangoWebProject1\DjangoWebProject1\urls.py", line 3, in <module> 
    from . import views 
ImportError: cannot import name views 
Press any key to continue . . . 

我該如何解決這個問題?


enter image description here


相關的源碼

urls.py

from django.conf.urls import url 

from . import views 

urlpatterns = [ 
    url(r'^articles/2003/$', views.special_case_2003), 
    url(r'^articles/([0-9]{4})/$', views.year_archive), 
    url(r'^articles/([0-9]{4})/([0-9]{2})/$', views.month_archive), 
    url(r'^articles/([0-9]{4})/([0-9]{2})/([0-9]+)/$', views.article_detail), 
] 
+0

你做了哪些步驟找到一個上手的假設下工作?你在項目目錄中有什麼文件? –

+0

http://stackoverflow.com/questions/42711286/cannot-import-name-patterns-django/42767618?noredirect=1#comment72655187_42767618 – anonymous

+0

@PenguinBrian,截圖添加。 – anonymous

回答

0

嘗試from app import views

我,你urls.py是在DjangoWebProject1目錄/包

1
from django.conf.urls import url 

    from app import views 
    #name of your app 
    urlpatterns = [ 
    url(r'^articles/2003/$', views.special_case_2003), 
    url(r'^articles/([0-9]{4})/$', views.year_archive), 
    url(r'^articles/([0-9]{4})/([0-9]{2})/$', views.month_archive), 
    url(r'^articles/([0-9]{4})/([0-9]{2})/([0-9]+)/$', 
    views.article_detail), 
    ]