I have this problem where I navigate from my home page (index.html)  to 
another page 
new_page.html) but the data input on new_page.html is not being read by 
Python. It seems as if at that point the HTML controls do not exist or are 
not being rendered and so I am unable to read the values in the text box 
and text area control.

Can someone help. Here are my source files

File name: layout.html
Comment: This is a template HTML page

{% load static %}

<!DOCTYPE html>

<html lang="en">
    <head>
        <title>{% block title %}{% endblock %}</title>
        <link rel="stylesheet" 
href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"; 
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh"
 
crossorigin="anonymous">
        <link href="{% static 'encyclopedia/styles.css' %}" 
rel="stylesheet">
    </head>
    <body>
        <div class="row">
            <div class="sidebar col-lg-2 col-md-3">
                <h2>Wiki</h2>
                <form>
    {% csrf_token %}
                  </form>
                <div>
                    <a href="{% url 'index' %}">Home</a>
                </div>
                <div>                    
<a href="{% url 'new_page'%}">Create New Page</a>
                </div>
                <div>
                    Random Page
                </div>
                {% block nav %}
                {% endblock %}
            </div>
            <div class="main col-lg-10 col-md-9">
                {% block body %}
                {% endblock %}
            </div>
        </div>

    </body>
</html>

File name: index.html
Comment: default home page

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

{% block title %}
    Encyclopedia
{% endblock %}

{% block body %}

{% endblock %}

File name: new_page.html
Comments: This is the page with the controls where I cannot read the 
information typed by the user

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

{% block title %}
    Encyclopedia
{% endblock %}

{% block body %}
    <h1>New Wiki Entry</h1>
        <label>Entry Title: </label> <input type="text" name="title_box" 
id="title_box"><br>
        <label>Markdown Text for entry:</label><br> 
<textarea name="entry_details" id="entry_details" rows="3" 
cols="10"></textarea><br> 
        <button type ="button" class="btn btn-primary btn-lg"formaction = 
"{% url 'add_entry' %}"> Add Entry</button>
<a href = "{% url 'add_entry' %}"> Add Entry </a>
{% endblock %}

File name: urls.py

from django.urls import path

from . import views

urlpatterns = [
    path("", views.index, name="index"),
    path("new_page",views.new_page,name="new_page"),
    path("add_entry",views.add_entry,name="add_entry")     
]


File name: views.py

from django.shortcuts import render
from django.http import HttpResponse



def index(request):
    return render(request, "encyclopedia/index.html")

    
def new_page(request):
    return render(request,"encyclopedia/new_page.html")

    
def add_entry(request):
     #entry_title = request.POST.get('title_box')
     #entry_contents = request.POST.get('entry_details')
     #entry_title = request.GET["title_box"]
     #entry_contents = request.GET["entry_details"]
     entry_title = "Title"
     entry_contents = "Contents"
     
     if 'title_box' in request.GET:
              entry_title = request.GET.get('title_box')
              print("Found in GET...")
     if 'title_box' in request.POST:
              entry_title = request.POST.get('title_box')
              print("Found in POST...")
     
         
     print(f"entry_title: {entry_title}")
     print(f"entry_contents: {entry_contents}")
     
     
     return HttpResponse("Add Wiki Entry")

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/472d845b-6bf8-463c-999a-4209a9fcaf80n%40googlegroups.com.

Reply via email to