Wednesday, November 6, 2019

unable to render Template Tags

I have been unable to render Template Tags.  even though it is present in my html file it just gets ignored i don't know why

Screenshot (135).png




what I'm trying to achieve: I'm trying to create dependent dropdowns for my foreign keys. So based on what i select in fl_no the park_bay value shows the corresponding value related to that

i have successfully created the ajax requests but the html that is supposed to load into the dropdown for park_bay is getting ignored

my views.py file:

"
from django.shortcuts import render,redirect
from django.views.generic.base import TemplateView
from status.forms import StatusForm
from status.models import FlightStatus
from django.views.generic import ListView, CreateView, UpdateView
from postlog.models import Flight
from django.urls import reverse_lazy
# Create your views here.
class StatusPageView(CreateView):

template_name = "status/home.html"
model = FlightStatus
form_class = StatusForm
success_url = reverse_lazy('status') 

def load_park_bay(request):
    flightid = request.GET.get('flight1')
    parks = Flight.objects.filter(fl_no='flightid').order_by('park_bay')
    context = {'parks': parks}
    return render(request, 'status/park_bay_dropdown_list.html', context)
"
my urls.py file:

"
from django.urls import path,include
from . import views
from django.contrib.staticfiles.urls import staticfiles_urlpatterns

urlpatterns = [
    path('', views.StatusPageView.as_view(), name='status'),
    path('ajax/load-park/', views.load_park_bay, name='ajax_load_park'),
]
"

the page where the form is being rendered home.html:

"
{% extends 'base_template1.html' %}
{% load static from staticfiles %}
{% load crispy_forms_tags %}

<!DOCTYPE html>

{% block title %} Status {% endblock %}

{% block content %} 
<button type="button" class="butra button1ra" data-toggle="modal" data-target="#Add_Modal">Add Flight Status</button> 
<div class="modal fade" id="Add_Modal" tabindex="-1" role="dialog" aria-labelledby="Add_ModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="AddModalLabel">Flight Details</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <form method="post" id="statusForm" data-parks-url="{% url 'ajax_load_park' %}" novalidate>
        {% csrf_token %}
        {{ form|crispy }}
<div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Add Details</button>
      </div>
</form>
  </div>
    </div>
  </div>
</div>

"
the html template which gets loaded into the park_bay options park_bay_dropdown_list.html:

"
{% load static from staticfiles %}
{% load crispy_forms_tags %}

<option value="">---------</option>
{% for park in parks %}
<option value="{{ park.fl_no }}">{{ park.park_bay }}</option>
{% endfor %}

"


Screenshot (137)_LI.jpg



only this one line gets added
and the rest of the lines present in the html file gets ignored
since they have template tags

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c2c1b96b-69fe-4df2-8413-449a8d336f69%40googlegroups.com.

No comments:

Post a Comment