Неопределенные название фильма и название города в HTML-шаблоне Seats, несмотря на передачу JavaScript и URL в Django-приложении
вот мой html-код shows.html
{% for cinema_hall in cinema_halls %}
<div>
<h2>{{ cinema_hall.name }}</h2>
<div class="show-container" id="show-container-{{ cinema_hall.id }}">
<!-- Loop through shows for each cinema hall -->
{% for show in shows %}
{% if show.cinemahall == cinema_hall %}
<div class="show-box" data-cinema_hall_id="{{ cinema_hall.id }}" data-show_id="{{ show.id }}">
Show: {{ show.timings }}
<br>
₹ {{ show.price }}
</div>
{% endif %}
{% endfor %}
</div>
</div>
{% endfor %}
и вот его js-код
function filterShowsByDate(date) {
const movieName = '{{ movie_name }}'; // Replace with actual movie name
const city = '{{ request.GET.city }}'; // Replace with actual city name
$.ajax({
url: `/shows/${movieName}/filter/${date}/?city=${city}`,
type: 'GET',
success: function(response) {
// Clear existing show containers
$('.show-container').empty();
// Loop through the filtered shows and display them
response.shows.forEach(function(show) {
const showBox = `<div class="show-box" data-show-id="${show.id}" data-cinema-hall-id="${show.cinemahall_id}">Show: ${show.timings} <br> ₹ ${ show.price } </div>`;
$('#show-container-' + show.cinemahall_id).append(showBox);
});
$('.show-box').click(function(event) {
event.preventDefault(); // Prevent default behavior
const showId = $(this).data('show-id');
const cinemaHallId = $(this).data('cinema-hall-id');
const movieName = $(this).data('movie-name');
const cityName = $(this).data('city-name');
// Redirect to seats page with appropriate parameters
window.location.href = `/seats/?show_id=${showId}&cinema_hall_id=${cinemaHallId}&movie_name=${encodeURIComponent(movieName)}&city_name=${encodeURIComponent(cityName)}`;
});
},
error: function(xhr, errmsg, err) {
console.log(errmsg);
}
});
}
и это views.py
def filter_shows_by_date(request, movie_name, selected_date):
selected_city = request.GET.get('city')
# Filter shows based on movie name, city, and selected date
shows = Show.objects.filter(movie__name=movie_name, city__name=selected_city, date=selected_date)
# Prepare data to be sent as JSON response
shows_data = list(shows.values())
response = {
'movie_name': movie_name,
'shows': shows_data,
'selected_date': selected_date,
}
return JsonResponse(response)
def seats(request):
show_id = request.GET.get('show_id')
cinema_hall_id = request.GET.get('cinema_hall_id')
movie_name = request.GET.get('movie_name')
city_name = request.GET.get('city_name')
# Retrieve show details
show = Show.objects.get(id=show_id)
# Retrieve cinema hall details
cinema_hall = CinemaHall.objects.get(id=cinema_hall_id)
context = {
'show': show,
'cinema_hall': cinema_hall,
'movie_name': movie_name, # Pass movie name
'city_name': city_name # Pass city name
}
return render(request, 'screen/seats.html', context)
и это urls.py
path('shows/<str:movie_name>/', views.shows, name='shows'),
path('shows/<str:movie_name>/filter/<str:selected_date>/', views.filter_shows_by_date, name='filter_shows_by_date'),
path('seats/',views.seats, name='seats' ) ,
Теперь я хочу, чтобы при нажатии на соответствующий div show пользователь попадал в seats.html, который работает хорошо, но в seats.html я хочу, чтобы он показывал фильм, перед фильмом, город перед городом и т.д. вот код seats.html
<p>
Movie name: {{ movie_name }} <br>
City: {{ city_name }} <br>
Cinema hall: {{ cinema_hall.name }} <br>
Date: {{ show.date }} <br>
<!-- Add other relevant show information here -->
</p>
и я не получаю вещи здесь и в url также название фильма и название города не определены, так что, пожалуйста, помогите мне