Everything is working properly in terms of editing and redirects, however there is a strange occurence where multiple extra empty lines are added between each line of the markdown content everytime the edit page is called. This makes editing difficult, as there are many blank lines between each line of content in the page.

Edit: Apparently \r is added to the lines, but I still dont understand what is happening exactly: https://www.reddit.com/r/cs50/comments/j4l64f/cs50web_project1_wiki_extra_line_breaks_being/ provides one solution.

The relevant code is below:


class EditPageForm(forms.Form):
    markdown = forms.CharField(label="Edit Page Content", widget=forms.Textarea(attrs={'class': "form- 
               control"}), required=False)

def edit(request, title):
    if request.method == 'GET':
        initial = {"markdown":util.get_entry(title.capitalize())}
        return render(request, 'encyclopedia/edit.html', {
            "title": title.capitalize(),
            "form": EditPageForm(initial = initial),
            "error": None
    form = EditPageForm(request.POST)
    if form.is_valid():
        markdown = form.cleaned_data["markdown"]
        util.save_entry(title, markdown)
        return redirect('wikipage', title = title)
        return render(request, 'encyclopedia/edit.html', {
            "form": form,
            "error": "Something went wrong."


{% extends "encyclopedia/layout.html" %}

{% block title %}
{% endblock %}

{% block body %}
    <h1>Edit {{title}}</h1>
    <form  method="post" class="form-group col-md-10">
        {% csrf_token %}
        <input type="submit" class="btn btn-primary">
    {% if error != None %}
    <div class="alert alert-danger">
    {% endif %}
{% endblock %}
  • The link you posted has the perfect answer – Vsjain Jan 26 at 12:04

You must log in to answer this question.

Browse other questions tagged .