Eric
Eric

Reputation: 839

Why got type error :takes 1 position argument but 2 were given?

I have faced a problem with my django project. It is as following:

Get Result: __init__() takes 1 positional argument but 2 were given

My code:

urls.py

url(r'^_get_weather', views._get_weather, name='_get_weather')

views.py

def _get_weather(request):
    r = urllib.request.urlopen('http://api.openweathermap.org/data/2.5/weather?APPID=$API&q=Hongkong')
    s = r.read().decode('utf-8')
    j = json.loads(s)
    temp='Current tempearture: {:.2f}'.format(j['main']['temp'] - 273.15)
    return HttpRequest(temp)

Upvotes: 1

Views: 647

Answers (1)

Moses Koledoye
Moses Koledoye

Reputation: 78546

Your view function should return an HttpResponse not an HttpRequest.

Upvotes: 6

Related Questions