Djangoの最初のビューでサードパーティのWebサービスを呼び出し、指定されたURIのHTMLページをPDFに変換しています。 (pdfcrowd、具体的には)。私がWebサービスを提供するURIは、2番目のDjangoビューに対応します。したがって、私が最初のビューからサードパーティのWebサービスを呼び出すと、Webサービスはurl(2番目のビューに対応)のページのリクエストを自分のサーバに送信し、結果のHTMLをPDFに変換して返します最初のビューにPDFファイルを表すバイト。 (下のコードを参照してください)サーバーに照会する外部WebサービスでDjango runserverがハングしています
しかし、Django runserverはこれでハングアップしますが、parrallelの実行を行わず、1つのリクエスト(2番目のビューに対応)に取り組むことができないと仮定しています。ビューはまだ実行中です&待機中です。また、Gunicornを実行しているプロダクションサーバでうまくいくと仮定しています.Gunicornは、並列処理をうまく処理する必要があります。
開発マシンでrunserverでこのコードを使用できるようにするには、うまくいきませんか?
class PdfMenuView(View):
def get(self, request, *args, **kwargs):
# I actually reverse a urlconf to get the full url, but show this as hardcoded for simplicity
prePdfHtmlUrl = "http://1.2.3.4:8080/url-to-convert/" # my router forwards 8080 to my machine to enable testing with external web services.
try:
# create an API client instance
client = pdfcrowd.Client(settings.PDFCROWD_USERNAME, settings.PDFCROWD_KEY)
# convert a web page and store the generated PDF to a string
pdf_string = client.convertURI(prePdfHtmlUrl) # this is where it gets hung up, since the client will cause the webserver to query the URI I provide it in order to get the page to convert, but this view is still tying up the runserver execution so the second view can't execute
except:
. . .
--threadedパラメータを指定したrunserver_plusは私のために機能します!ありがとう。私はdjango-devserverを使いますが、runserverコマンドをどのように置き換えるのが好きではありません。私はpycharmの組み込みデバッガで使用していますので、そのままにしておきたいと思います。 –