我是django-ajax的新学徒。我不知道如何在django视图中使用popup ajax。我创建了两个html文件list.html
和detail.html
。
我的问题是,当我点击任何产品以使用ajax使用弹出格式显示产品详细信息时,我打开list.html
。
所以请告诉view,jquery,html和ajax
中需要进行哪些更改view.py
def show_product(request, product_slug, template_name="catalog/product.html"):
p = get_object_or_404(Product, slug=product_slug)
categories = p.categories.filter(is_active=True)
page_title = p.name
meta_keywords = p.meta_keywords
meta_description = p.meta_description
return render_to_response(template_name, locals(),context)
def list_product(request):
queryset_list = Product.objects.all() #.order_by("-timestamp")
paginator = Paginator(queryset_list, 1) # Show 25 contacts per page
page_request_var = "page"
page = request.GET.get(page_request_var)
try:
queryset = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
queryset = paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
queryset = paginator.page(paginator.num_pages)
context = {
"object_list": queryset,
"name": "List",
"page_request_var": page_request_var
}
return render(request, "catalog/list.html", context)
list.html
{% extends "base.html" %}
{% block content %}
<div class="signup">
<div class='col-sm-6 col-sm-offset-3'>
<center><h1>{{ name }}</h1></center>
{% for obj in object_list %}
<div class="caption">
<h3>{{ obj.name }}</h3>
<p>{{ obj.content|linebreaks|truncatechars:120 }}</p>
<p><a href="{{ obj.get_absolute_url }}" class="btn btn-primary" role="button">View</a></p>
</div>
<hr/>
{% endfor %}
<div class="pagination">
<span class="step-links">
{% if object_list.has_previous %}
<a href="?{{ page_request_var }}={{ object_list.previous_page_number }}">previous</a>
{% endif %}
<span class="current">
Page {{ object_list.number }} of {{ object_list.paginator.num_pages }}.
</span>
{% if object_list.has_next %}
<a href="?{{ page_request_var }}={{ object_list.next_page_number }}">next</a>
{% endif %}
</span>
</div>
</div>
{% endblock content %}
product.html
{% extends "base.html" %}
{% block content %}
<body>
<div class="signup">
<h1>{{ p.name }}</h1>
Brand: <em>{{ p.brand }}</em> <br/><br/>
SKU: {{ p.sku }} <br/> <br/>
In categor{{ categories.count|pluralize:"y,ies" }}:
{% for c in categories %}
<a href="{{ c.get_absolute_url }}">{{ c.name }}</a>
{% if not forloop.last %}, {% endif %}
{% endfor %} <br/><br/>
{% if p.sale_price %}
Was: <del>$ {{ p.old_price }}</del> <br/>
Now: $ {{ p.price }}
{% else %}
Price: $ {{ p.price }}
{% endif %} <br/><br/>
<div class="cb"><br /><br/></div>
<h3>Product Description</h3>
{{ p.description }}
</div>
</body>
{% endblock content %}