私は Django に関連するすべての初心者に過ぎないので、混乱を招く説明を前もってお詫びします。eコマースモジュールが添付されたDjangoベースのWebサイトで、いくつかのページ読み込みの問題を解決しようとしています。
最初のページ読み込み時間は約 5 秒と非常に長く、その後はすべてがスムーズに進みます。
- これは firebug からのスクリーンショットです: http://i.imgur.com/WEuYwq1.jpg
- 開発環境へのリンク: http://bit.ly/13G7jNp (製品ページ)
この膨大な読み込み時間は、製品に関連するすべてのページ (私の場合は単一の製品ページとカート) で発生しています。奇妙なことに、リストは問題ありません(カテゴリページ)。
次の推測では、読み込み時間は製品関連のクエリが原因であると考えられるため、コードをさらに検索したところ、「product_view」定義を含む main.py ファイルにたどり着きました。
コードは次のようになります。
def product_view(request,shortcode,product_id,variation_id,stub):
product = get_object_or_404(Product.unmoderated.select_related(),pk=product_id)
variation = get_object_or_404(ProductVariation.objects.select_related(),pk=variation_id)
print variation.__dict__
if not product.active:
c = {}
return render_to_response('main/product_inactive.html', c, context_instance=RequestContext(request))
links = ['main_product_view','main_product_variation'+str(variation.id)]
c = {'links':links, 'product':product, 'variation':variation, 'categories':get_categories(), 'brands':get_brands(), 'title':product.name}
c.update(csrf(request))
return render_to_response('main/product.html', c,
context_instance=RequestContext(request))
def product_view_json(request,shortcode,product_id,variation_id,stub):
try:
product = get_object_or_404(Product,pk=product_id)
variation = get_object_or_404(ProductVariation,pk=variation_id)
thumbnail = get_thumbnail(variation.image, '220x220', crop='center', quality=80)
d = {"title":product.name, "brand":product.merchant.name, "price":str(product.base_price+variation.price), "image":thumbnail.url}
out = json.dumps(d)
r = HttpResponse(out)
r['Access-Control-Allow-Origin'] = '*';
return r
except:
return HttpResponse("Error")
この時点で、私は道に迷いました。この問題を解決するための正しい道を進んでいるかどうか、または他に何をすべきかわかりません。
また、欠落している画像がいくつかありますが、まだそれらを打ち負かしていませんが、現時点では完全に関連しているわけではありません. さらに、memcache が有効になり、静的テンプレート ファイルはページの読み込み時間にまったく影響を与えず (テンプレートはテキストのみに取り除かれます)、Apache 環境で mod_pagespeed モジュールが有効になります。
これに関するご意見をいただければ幸いです。ありがとうございました!