简体   繁体   中英

Django How do i display different pages on one html

I am currently making a movie reservation site using django. The first page lists the currently screened movies. If I click on one of them, then go to the page where shows the details of the movie. If there are movie A, B, and C that is currently being screened.

For example

If I click A, I want to have detailed information about A movie on the movie details information page.

If I click B, I want to have detailed information about B movie on the movie details information page.

If I click C, I want to have detailed information about C movie on the movie details information page.

I want to make it not using javascript!! only using django and html!!

Could you please help me?

moviehome.html / Showing Current playing movies and Coming soon movie

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <h1>Current Playing</h1>
    Hi, {{user}}! <a href="{% url 'signout' %}">LOG_OUT</a><br>
    {% for movieinfos in movie.all %}
        <a href="{% url 'realinfo'%}"><img src="{{movieinfos.movie_poster.url}}" width=100px height=150px></a><br>
        {{movieinfos.movie_age}}
        <a href="{% url 'realinfo'%}">{{movieinfos.movie_name}}</a><br>
        장르 | {{movieinfos.movie_genre}}<br>
        감독 | <a href="{% url 'directorinfo' %}">{{movieinfos.movie_director}}</a><br>
        출연 | <a href="{% url 'actorinfo' %}">{{movieinfos.movie_actor1}}</a> , <a href="{% url 'actorinfo' %}">{{movieinfos.movie_actor2}}</a>
        <br>
    {% endfor %}
    <h1>Comming Soon</h1>
    {% for movieinfos in movie1.all %}
        <a href="{% url 'realinfo'%}"><img src="{{movieinfos.movie_poster.url}}" width=100px height=150px></a><br>
        {{movieinfos.movie_age}}
        <a href="{% url 'realinfo'%}">{{movieinfos.movie_name}}</a><br>
        장르 | {{movieinfos.movie_genre}}<br>
        감독 | <a href="{% url 'directorinfo' %}">{{movieinfos.movie_director}}</a><br>
        출연 | <a href="{% url 'actorinfo' %}">{{movieinfos.movie_actor1}}</a> , <a href="{% url 'actorinfo' %}">{{movieinfos.movie_actor2}}</a>
        <br>
    {% endfor %}
</body>
</html>

view.py

def moviehome(request):
    if request.user.is_authenticated:
        movie = movieinfo.objects.filter(movie_playing =1)
        movie1 = movieinfo.objects.filter(movie_playing=2)

        return render(request, 'movie/moviehome.html', {
            'movie' : movie,
            'movie1' : movie1,
            'user' : request.user
        })
    else:
        return render(request, 'movie/not_logged_in.html')

def realinfo(request):
    return render(request, 'movie/realinfo.html')
#What code do i have to put in here?
def actorinfo(request):
    return render(request, 'movie/actorinfo.html')
#What code do i have to put in here?
def directorinfo(request):
    return render(request, 'movie/directorinfo.html')
#What code do i have to put in here?

moviehome.html -> realinfo.html showing movie's details

moviehome.html -> actorinfo.html showing actor's details

moviehome.html -> directorinfo.html showing director's details

You should look into class based views, specifically detail view. You have to make template for detail view and then pass information from database/models to that template through views.py.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM