0

I'm on the Final Project for CS50 and trying to make a simple website to type in General Tasks and get information within different Subjects. I decided to use Flask over Django, however now I'm stuck on opening a new personalized html file when clicked on a link, depending on which Subjects link the users clicks on. I know in Django you can add the urls as f.ex. entry/<title>, which then opens that specific entry's information. I couldn't find if there's anything similar for Flask, maybe with Javascript. Thanks for your help!

Here's the Subjects html, where I tried to do something like <td><a href="entry.html/{{ subject['subject'] }}">{{ subject['subject'] }}</a>

{% extends "layout.html" %}

{% block title %}
    Subjects
{% endblock %}

{% block main %}
<h1> Subjects </h1>
<hr>
<table class = "table table-striped table">
    <tr>
        {% for subject in subjects %}
            <td><a href="entry.html/{{ subject['subject'] }}">{{ subject['subject'] }}</a></td>
        {% endfor %}
    </tr>

<form action="/subjects" method="POST">
    <div class="form-group group">
        <input autocomplete="off" autofocus class="form-control" name="subject" placeholder="Subject" type="text">
    </div>
<button class="btn btn-primary b" type="submit" style="margin-bottom:30px">Add Subject</button>
</form>

{% endblock %}

Subjects Page

This is the Python path to it:

@app.route("/entry", methods=["GET"])
@login_required
def entry(title):
    title == request.args.get("subject['subject']")
    return render_template("entry.html", title=title)

And this is what I want the entry.html/{{subject['subject']}} to look like, depending on which Subject is clicked on:

{% extends "layout.html" %}

{% block title %}
<head>

    <title> {{title}} </title>

</head>
{% endblock %}
2
  • Are you doing CS50W or CS50X?
    – Vsjain
    Sep 24, 2020 at 8:08
  • This Final Project is for CS50x
    – abbanator
    Sep 24, 2020 at 16:15

1 Answer 1

1

The path should be:

@app.route("/entry/<title>", methods=["GET"])
@login_required
def entry(title):
    return render_template("entry.html", title=title)

This will do the work. If this work then please check the tickmark.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .