AmirNakhostin
AmirNakhostin

Reputation: 27

TypeError at /news/ , html() takes no arguments

I am a beginner in Django. Can you guys tell me why I am getting this error. code:

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)

Error:

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)

Upvotes: 1

Views: 338

Answers (1)

alecxe
alecxe

Reputation: 473763

According to the documentation:

A view function, or view for short, is simply a Python function that takes a Web request and returns a Web response.

In other words, your function(s) should accept a request argument:

def html(request):
    html = "<html><body> %s </body></html>" % news()
    return HttpResponse(html)

Upvotes: 1

Related Questions