It's a python error.
First argument of method on an object is always the object itself,
named self by convention. For exemple,
class Greet:
def hello(self, name):
print("Hello %s!" % name)
Python will take care of passing this argument when you call the method.
2016-10-24 20:52 GMT+02:00 Carlos García <carlosgrgr@gmail.com>:
> Hi, I'm creating a app which do a request to a API and the result is showing
> on a web page. My code is this:
>
> Models.py
> from django.db import models
> from django.template import Template, Context
> from django.http import HttpResponse
> import requests, json
>
> class HotelService(models.Model):
>
> def getAvailAndRates(getAvailAndRatesRQ):
> datos = json.dumps(getAvailAndRatesRQ, ensure_ascii=False)
>
> cabeceras = {
> 'Content-Type': 'application/json',
> 'action': 'getavailandrates',
> 'format': 'json',
> 'Accept-Encoding': 'gzip'
> }
> url =
> 'http://connectivity.dingus-services.com/services/v4/hotelservice.ashx'
> response = requests.post(url, data=datos, headers=cabeceras)
>
> if response.status_code == 200:
> results = response.json()
> else:
> results = "Error"
> return results
>
>
> views.py
> from django.shortcuts import render
> from django.http import HttpResponse
> from .models import HotelService
> import json
>
>
> # Create your views here.
> def show(request):
> rq = {"Credentials": {
> 'UserName': '*******',
> 'Languaje': 'es',
> 'Password': '*******',
> },
> 'GetAvailAndRatesRQ': {
> 'NotGetCancellationInfoCollection': False,
> 'GetMultiGroupRates': True,
> 'RQRec':[{
> 'HotelCode': 'ROL01',
> 'RQID': 1,
> 'RoomRQ': [{
> 'PaxAgeList':[30,
> 30,],
> 'CH': 0,
> 'RQID': 1,
> 'AD': 2,
> 'RoomCode': 'FAM',
> 'CU': 0,
> 'NoRooms': 1,
> 'BoardCode': 'TI',
> }]
> }],
> 'NotGetChargeInfoCollection': False,
> 'PromotionCodeList': [],
> 'GetPromotionsCollection': True,
> 'DateTo': '2016-11-5',
> 'IncludedPromotionsInOnlyBar': False,
> 'DateFrom': '2016-10-30',
> 'GetHotelRS': False,
> 'Languaje': 'es',
> 'GetHotelDetails': False,
> 'GetHotelsWithoutAllotment': True,
> 'OnlyBar': False,
> 'NotGetDailyPriceCollection': True,
> 'ExactRoomMatch': False,
> 'GroupRateList': [],
> 'CustomerCode': 'WEB',
> 'Criteria': [],
> }
> }
> product = HotelService.getAvailAndRates(rq)
>
> return HttpResponse(product)
>
> It's giving the error: unbound method getAvailAndRates() must be called with
> HotelService instance as first argument (got WSGIRequest instance instead).
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscribe@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/cdc47059-16eb-4d1a-8de6-5d3519d06508%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
--
Cordialement, Coues Ludovic
+336 148 743 42
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAEuG%2BTa-rReTW1_dg%2BhQsiBEf_FUJtYAh%3DQPnmHmB%3DWgv%2B6gGw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment