/ myapp / hello / hello()中的TypeError恰好有2个参数(给定1个)

时间:2016-10-05 06:29:44

标签: python django

ecomstore / settings.py

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'uploader',
    'myapp',
)

ecomstore / urls.py

from django.conf.urls import patterns, include, url
from django.contrib import admin
from django.conf import settings
from django.conf.urls.static import static
admin.autodiscover()

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'ecomstore.views.home', name='home'),
    # url(r'^blog/', include('blog.urls')),

    url(r'^admin/', include(admin.site.urls)),
    url(r'^catalog/$', 'ecomstore.views.catalog'),
    url(r'^myapp/', include(myapp.urls)),
    url(r'^upload/$', 'uploader.views.home', name = 'imageupload'),
) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

的myapp / urls.py

from django.conf.urls import patterns, include, url

urlpatterns = patterns('',
    url(r'^hello/', 'myapp.views.hello', name = 'hello'),
)

的myapp / views.py

from django.shortcuts import render
from django.http import HttpResponse

# Create your views here.

def hello(request, number):
    text = "<h1>welcome to my app number %s!</h1>"% number
    return render(request, "myapp/template/hello.html", {})
    return HttpResponse(text)
更改网址后更改网址(r&#39; ^ myapp /&#39;,包含(&#39; myapp.urls&#39;),当我输入网址localhost:8000 / myapp / hello / it&#39; s在/ myapp / hello /

中抛出TypeError

hello()只需要2个参数(给定1个)

请指导我

感谢。

1 个答案:

答案 0 :(得分:0)

你缺少引号:

include('myapp.urls')

那个或导入myapp(未在你的urls.py上导入)