2013-03-26 82 views
0

我安裝Python和Django和只是想建立一個簡單的應用程序「mysite的」Django的NameError

我創建了根文件夾中的views.py,而我的urls.py是根/ mysite的/ 當我調用/ hello它給我以下錯誤。我應該怎麼做才能解決它?

NameError at /hello 
name 'hello' is not defined 
Request Method: GET 
Request URL: ~~:8000/hello 
Django Version: 1.5 
Exception Type: NameError 
Exception Value:  
name 'hello' is not defined 
Exception Location: c:\Python27\Django-1.5\mysite\mysite\urls.py in <module>, line 17 
Python Executable: c:\Python27\python.exe 
Python Version: 2.7.2 
Python Path:  
['c:\\Python27\\Django-1.5\\mysite', 
'c:\\Python27\\lib\\site-packages\\setuptools-0.6c11-py2.7.egg', 
'c:\\Python27\\lib\\site-packages\\pymysql-0.3-py2.7.egg', 
'C:\\Windows\\system32\\python27.zip', 
'c:\\Python27\\DLLs', 
'c:\\Python27\\lib', 
'c:\\Python27\\lib\\plat-win', 
'c:\\Python27\\lib\\lib-tk', 
'c:\\Python27', 
'c:\\Python27\\lib\\site-packages'] 
Server time: Tue, 26 Mar 2013 18:40:41 +0530 
Traceback Switch to copy-and-paste view 

c:\Python27\lib\site-packages\django\core\handlers\base.py in get_response 
        response = middleware_method(request) 
... 
▶ Local vars 
c:\Python27\lib\site-packages\django\middleware\common.py in process_request 
      if (not urlresolvers.is_valid_path(request.path_info, urlconf) and 
... 
▶ Local vars 
c:\Python27\lib\site-packages\django\core\urlresolvers.py in is_valid_path 
     resolve(path, urlconf) 
... 
▶ Local vars 
c:\Python27\lib\site-packages\django\core\urlresolvers.py in resolve 
    return get_resolver(urlconf).resolve(path) 
... 
▶ Local vars 
c:\Python27\lib\site-packages\django\core\urlresolvers.py in resolve 
      for pattern in self.url_patterns: 
... 
▶ Local vars 
c:\Python27\lib\site-packages\django\core\urlresolvers.py in url_patterns 
     patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module) 
... 
▶ Local vars 
c:\Python27\lib\site-packages\django\core\urlresolvers.py in urlconf_module 
      self._urlconf_module = import_module(self.urlconf_name) 
... 
▶ Local vars 
c:\Python27\lib\site-packages\django\utils\importlib.py in import_module 
    __import__(name) 
... 
▶ Local vars 
c:\Python27\Django-1.5\mysite\mysite\urls.py in <module> 
         ('^hello/$', hello), 
... 
+0

什麼是你的urls.py?有/你好嗎? – MichaelB 2013-03-26 13:21:45

回答

0
c:\Python27\Django-1.5\mysite\mysite\urls.py in <module> 
         ('^hello/$', hello), 

您還沒有定義hello,我相信你既可以進口興田功能或引用它作爲一個字符串在下面的網址線

from mysite.myapp.views import hello 

'mysite.myapp.views.hello' 
3

變化.py

('^hello/$', hello), 

('^hello/$', 'views.hello'), 

,或者如果您使用的前綴然後做

('^hello/$', 'hello'), 

或做

from views import hello 
+0

他錯過了請求中的最終'/'或缺少'^ hello $'的路由 – MichaelB 2013-03-26 13:47:16