문제

I am still learning and none of the other questions answer my question, why do I have to have an HTTP Response?

def view(request):
        namesTickers = Company.objects.all().values('name', 'ticker')
        names, tickers = [], []
        for nameTicker in namesTickers:
                names.append(nameTicker['name']) 
                tickers.append(nameTicker['ticker']) 
        nameTickerDict = dict(zip(names, tickers))
        print nameTickerDict

        if 'ticker' in request.POST and request.POST['ticker']:
                q = request.POST['ticker']

                context = {}
                context['companies'] = json.dumps(nameTickerDict)
                context['companyInfo'] = Company.objects.filter(ticker__icontains=q)
                context['financial'] = Financials.objects.filter(ticker__icontains=q).order_by('-year')

                return render( request, "companies/view.html",[context])
도움이 되었습니까?

해결책

Because HTTP is a request/response mechanism. You get a request and you must respond to it. It doesn’t have to be a successful response, though. If you cannot respond meaningfully without a ticker, you may return an error page instead. Or, if you have a form where the user enters a ticker and submits that to your view, then you probably want to return the user back to the same form but with an error message. If that is the case, Django’s forms framework will help you.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top