我是Django的初学者。你能告诉我为什么我会收到这个错误。 代码:
enter code here:
import feedparser
from django.http import HttpResponse
def news():
YahooContent = feedparser.parse ("http://news.yahoo.com/rss/")
for feed in YahooContent.entries:
print feed.published
print feed.title
print feed.link + "\n"
return
def html():
html = "<html><body> %s </body></html>" % news()
return HttpResponse(html)
错误:
TypeError at /news/
html() takes no arguments (1 given)
Request Method: GET
Request URL: this is not a url : (http://djangodefault.com:8000/news/)
Django Version: 1.6.5
Exception Type: TypeError
Exception Value:
html() takes no arguments (1 given)
答案 0 :(得分:1)
视图函数或简称视图只是一个Python函数 接受Web请求并返回Web响应。
换句话说,您的函数应该接受request
参数:
def html(request):
html = "<html><body> %s </body></html>" % news()
return HttpResponse(html)