未解决的 url 参考(python django)
Unresolved url reference(python django)
我有一个未解决的 URL 请求,不太确定是什么导致了这个问题。
我正在为我的上下文应用程序设置主页
我在views.py中的观点:
from django.http import HttpResponse
from django.shortcuts import render
def home(request):
return render(request, "homepage template.html")
我的 URL 在 urls.py:
from django.conf.urls import patterns, include, url
from django.contrib import admin
urlpatterns = patterns('',
# Examples:
url(r'^$', 'homepage.views.home'),
enter code here
浏览器报错:
No module named 'homepage'
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 1.7.5
Exception Type: ImportError
Exception Value:
No module named 'homepage'
Exception Location: C:\Python34\lib\importlib\__init__.py in import_module, line 109
Python Executable: C:\Python34\python.exe
Python Version: 3.4.3
Python Path:
['C:\Users\jodie\Desktop\NtokloMH',
'C:\Windows\SYSTEM32\python34.zip',
'C:\Python34\DLLs',
'C:\Python34\lib',
'C:\Python34',
'C:\Python34\lib\site-packages']
Server time: Sat, 7 Mar 2015 19:10:33 +0000
我以为我通过 views.py 和 urls.py 代码定义了模块,但是 pycharm 告诉我它无法解析 URL.
根据要求:
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'musicsearch',
)
如果 musicsearch
是您在 django 中自己创建的唯一已安装应用程序,并且 views.py 文件位于该目录中,则
urlpatterns = patterns('',
# Examples:
url(r'^$', 'homepage.views.home'),
enter code here
应该是
urlpatterns = patterns('',
# Examples:
url(r'^$', 'musicsearch.views.home'),
enter code here
否则,如果 homepage
是一个确实存在的应用程序,您需要将其添加到 INSTALLED_APPS
中:
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'musicsearch',
'homepage',
)
我有一个未解决的 URL 请求,不太确定是什么导致了这个问题。
我正在为我的上下文应用程序设置主页
我在views.py中的观点:
from django.http import HttpResponse
from django.shortcuts import render
def home(request):
return render(request, "homepage template.html")
我的 URL 在 urls.py:
from django.conf.urls import patterns, include, url
from django.contrib import admin
urlpatterns = patterns('',
# Examples:
url(r'^$', 'homepage.views.home'),
enter code here
浏览器报错:
No module named 'homepage' Request Method: GET Request URL: http://127.0.0.1:8000/ Django Version: 1.7.5 Exception Type: ImportError Exception Value: No module named 'homepage' Exception Location: C:\Python34\lib\importlib\__init__.py in import_module, line 109 Python Executable: C:\Python34\python.exe Python Version: 3.4.3 Python Path: ['C:\Users\jodie\Desktop\NtokloMH', 'C:\Windows\SYSTEM32\python34.zip', 'C:\Python34\DLLs', 'C:\Python34\lib', 'C:\Python34', 'C:\Python34\lib\site-packages'] Server time: Sat, 7 Mar 2015 19:10:33 +0000
我以为我通过 views.py 和 urls.py 代码定义了模块,但是 pycharm 告诉我它无法解析 URL.
根据要求:
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'musicsearch',
)
如果 musicsearch
是您在 django 中自己创建的唯一已安装应用程序,并且 views.py 文件位于该目录中,则
urlpatterns = patterns('',
# Examples:
url(r'^$', 'homepage.views.home'),
enter code here
应该是
urlpatterns = patterns('',
# Examples:
url(r'^$', 'musicsearch.views.home'),
enter code here
否则,如果 homepage
是一个确实存在的应用程序,您需要将其添加到 INSTALLED_APPS
中:
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'musicsearch',
'homepage',
)