Javascript Django web应用程序中的奇怪行为
我在Django应用程序中遇到了一个奇怪的bug,这几天来一直困扰着我 基本上,我的一个动态模板停止在临时服务器上渲染。在本地一切正常,当推送到我的登台服务器时,一切似乎都正常。但是,在点击了几个页面后,使用此模板导航回其中一个页面,它突然消失了。如果重新启动主管进程,模板将重新出现,但在导航到其他页面后再次消失 奇怪的是,当它消失时并不一致。有时导航到其他页面需要几次才能消失 模板本身具有动态生成的内容,但即使容器div也没有出现,因此我认为这不是上下文错误 关于它的另一点是,如果我停止我的主管进程并运行./manage.py runserver,那么问题似乎不会发生 我尝试过的事情:Javascript Django web应用程序中的奇怪行为,javascript,html,django,supervisord,Javascript,Html,Django,Supervisord,我在Django应用程序中遇到了一个奇怪的bug,这几天来一直困扰着我 基本上,我的一个动态模板停止在临时服务器上渲染。在本地一切正常,当推送到我的登台服务器时,一切似乎都正常。但是,在点击了几个页面后,使用此模板导航回其中一个页面,它突然消失了。如果重新启动主管进程,模板将重新出现,但在导航到其他页面后再次消失 奇怪的是,当它消失时并不一致。有时导航到其他页面需要几次才能消失 模板本身具有动态生成的内容,但即使容器div也没有出现,因此我认为这不是上下文错误 关于它的另一点是,如果我停止我的主
- 我使用django模板repl加载url并查看上下文 模板接收时,我希望呈现的所有数据似乎都在那里
def list(request):
projects = Project.objects.active()
order = request.GET.get('order', 'popular')
projects = projects.ordered_by(order)
search_q = request.GET.get('search_q')
if search_q:
project_query_terms = ['title', 'short_description', 'who_description']
username_query_terms = [
'user__userprofile__first_name',
'user__userprofile__last_name']
project_query = create_query(search_q, project_query_terms)
username_query = create_query(search_q, username_query_terms) & Q(
name_is_visible__exact=True)
projects = projects.filter(project_query | username_query)
if request.GET.get('sector'):
projects = projects.filter(sector__id=request.GET['sector'])
if request.GET.get('location'):
projects = projects.filter(
location=request.GET['location'],
location_public=True)
form = ProjectFilterForm
form = (form(request.GET, projects=projects)
if request.GET else form(projects=projects))
paginator = Paginator(projects, 9)
page = request.GET.get('page')
try:
projects = paginator.page(page)
except PageNotAnInteger:
projects = paginator.page(1)
except EmptyPage:
projects = paginator.page(paginator.num_pages)
amounts_by_project = Need.objects.amounts_by_project()
amounts_raised_by_project = MoneyDonation.objects.amounts_raised_by_project()
context = {
'body_id': 'project-list',
'projects': projects,
'form': form,
'order': order,
'amounts_by_project': amounts_by_project,
'amounts_raised_by_project': amounts_raised_by_project,
}
template = "_projects-content" if request.is_ajax() else "projects"
template = "projects/" + template + ".html"
return render(request, template, context)
projects-projects.html模板
{% extends 'projects/__base.html' %}
{% load image_tags staticfiles projects %}
{% block content %}
{% include 'projects/_projects-content.html' %}
{% endblock %}
{% block scripts %}
<script>
FCC.drawDonuts('.col-project');
jQuery(function updateWithFilters($){
function queryWithParams() {
var getParams = '';
$('#project-filter-form select').each(function(i) {
getParams += (i === 0) ? '?' : '&';
getParams += this.name + '=' + $(this).children('option:selected')[0].value;
});
$.get({% url 'projects' %} + getParams, function(res){
$("#projects-content").html(res);
updateWithFilters($);
FCC.drawDonuts('.col-project');
});
}
$('#project-filter-form select').change(function(e){
queryWithParams();
});
$('#reset-filters').click(function(e) {
e.preventDefault();
$('#project-filter-form select option:selected').each(function(){
$(this).prop('selected', false);
queryWithParams();
});
});
});
</script>
{% endblock %}
{%extends'projects/\uu base.html%}
{%load image_标记静态文件项目%}
{%block content%}
{%include'projects/_projects-content.html%}
{%endblock%}
{%block scripts%}
FCC.drawDonuts(“.col项目”);
jQuery(函数updateWithFilters($){
函数queryWithParams(){
var getParams='';
$(“#项目筛选表单选择”)。每个(函数(i){
getParams+=(i==0)?“?”:“&”;
getParams+=this.name+'='+$(this).children('option:selected')[0]。值;
});
$.get({%url'项目“%}+getParams,函数(res){
$(“#项目内容”).html(res);
updateWithFilters($);
FCC.drawDonuts(“.col项目”);
});
}
$(“#项目筛选表单选择”)。更改(函数(e){
queryWithParams();
});
$(“#重置过滤器”)。单击(函数(e){
e、 预防默认值();
$('#项目筛选表单选择选项:选中')。每个(函数(){
$(this.prop('selected',false);
queryWithParams();
});
});
});
{%endblock%}
_projects-content.html
<div id='projects-content'>
{% include 'projects/_projects-filters.html' %}
{% include 'projects/_projects-projects.html' %}
</div>
{%include'projects/_projects-filters.html%}
{%include'projects/_projects-projects.html%}
_projects-projects.html
<section class="section hp-projects">
<div class="container">
<div class="row">
<div class="col-xs-12 sub-header">
<sub-header>
<h2>Browse all projects</h2>
</sub-header>
</div>
{% if not projects %}
<p>No projects match your search.</p>
{% endif %}
{% for project in projects %}
<div class="col-xs-12 col-sm-6 col-md-4">
{% include '_project-thumbnail.html' %}
</div><!--col-->
{% endfor %}
</div><!--row-->
<div class="row">
<div class="col-xs-12">
{% with projects as collection %}
{% include 'pagination.html' %}
{% endwith %}
</div>
</div>
</div><!--container-->
</section>
浏览所有项目
{%如果不是项目%}
没有与您的搜索匹配的项目
{%endif%}
{项目%中的项目为%}
{%include'\u project-thumboil.html%}
{%endfor%}
{%项目作为集合%}
{%include'分页.html%}
{%endwith%}
_project-thumbnail.html
{% load total staticfiles projects %}
<div class="project-container">
<header>
<a href="{% url 'project_detail' project.id %}" class="project">
<h5 class="project-title">{{ project.title }}</h5>
</a>
</header>
<figure>
<div class="img-wrap">
<a href="{% url 'project_detail' project.id %}" class="project">
<img class="img-responsive" src="{{ MEDIA_URL }}{{ project.profile_image }}" alt="project image" />
</a>
</div>
<figcaption>{{ project.short_description }}</figcaption>
</figure>
<div class="row three-donuts">
<div class="col-xs-6">
{% include "projects/_project-donate-thumbnail.html" %}
</div>
<div class="col-xs-6">
{% include "projects/_project-volunteer-thumbnail.html" %}
</div>
</div>
</div><!--box-container-->
<div id="project-{{ project.id }}-donate" class="col-project this-project-donate">
<span class="percentage">
{% if project.donate_aim %}
{{ project.donate_percent }}%
{% endif %}
</span>
</div>
<div class="equation">
£{{ project.donate_status }}
<span class="desired-amount">/ £{{ project.donate_aim }}</span>
</div>
<div class="button-link-wrapper">
{% if project.donate_aim %}
<a href="{% url 'project_donate' project.id %}" class="button graph-button donate">donate</a>
{% else %}
<span class="button graph-button donate deactivated">donate</span>
{% endif %}
</div>
{load total staticfiles projects%}
{{project.short_description}}
{%include“projects/_project-generate-thumbnail.html”%}
{%include“projects/_project-志愿者-thumbnail.html”%}
_project-donate-thumbnail.html是导航到其他页面后不呈现的模板
这是文件的内容,但正如我所说,在重新启动服务器后,一旦离开此页面,此文件中的任何内容都不会呈现。
然而_project-志愿者-thumbnail仍然完好无损。消失的只是捐赠的短尾
_project-project-thumbnail.html
{% load total staticfiles projects %}
<div class="project-container">
<header>
<a href="{% url 'project_detail' project.id %}" class="project">
<h5 class="project-title">{{ project.title }}</h5>
</a>
</header>
<figure>
<div class="img-wrap">
<a href="{% url 'project_detail' project.id %}" class="project">
<img class="img-responsive" src="{{ MEDIA_URL }}{{ project.profile_image }}" alt="project image" />
</a>
</div>
<figcaption>{{ project.short_description }}</figcaption>
</figure>
<div class="row three-donuts">
<div class="col-xs-6">
{% include "projects/_project-donate-thumbnail.html" %}
</div>
<div class="col-xs-6">
{% include "projects/_project-volunteer-thumbnail.html" %}
</div>
</div>
</div><!--box-container-->
<div id="project-{{ project.id }}-donate" class="col-project this-project-donate">
<span class="percentage">
{% if project.donate_aim %}
{{ project.donate_percent }}%
{% endif %}
</span>
</div>
<div class="equation">
£{{ project.donate_status }}
<span class="desired-amount">/ £{{ project.donate_aim }}</span>
</div>
<div class="button-link-wrapper">
{% if project.donate_aim %}
<a href="{% url 'project_donate' project.id %}" class="button graph-button donate">donate</a>
{% else %}
<span class="button graph-button donate deactivated">donate</span>
{% endif %}
</div>
{%if project.project\u aim%}
{{project.provide_percent}}
{%endif%}
英镑{project.ovate_status}
/英镑{project.donate_aim}
{%if project.project\u aim%}
{%else%}
捐赠
{%endif%}
同样,任何关于下一步的建议都会很有帮助