leo-the-manic avatar leo-the-manic committed 472aa32 Draft

Enhance data display in example app

Comments (0)

Files changed (2)

example/core/templates/base.html

     {% block content %}
         <form action="" method="post" >
             {% csrf_token %}
-            {% if form.is_valid %}
-                {{ form.as_p }}
-                <h2>Cleaned Data</h2>
-                {{ form.cleaned_data }}
-            {% else %}
-                {{ form.as_p }}
-            {% endif %}
+            {{ form.as_p }}
             <button class="btn">Submit</button>
         </form>
+        {% if form.is_valid %}
+            <div>
+                <h2>Cleaned Data</h2>
+                <pre>{{ cleaned_data }}</pre>
+            </div>
+        {% endif %}
+        {% if raw_post %}
+            <div>
+                <h2>Raw POST data:</h2>
+                <pre>{{ raw_post }}</pre>
+            </div>
+        {% endif %}
     {% endblock %}
     </div>
     {% include_jquery_libs %}

example/core/views.py

+import pprint
+
 from django.shortcuts import render_to_response
 from django.template import RequestContext
 
         else:
             form = FruitForm()
 
-    return render_to_response('base.html', {'form': form}, context_instance=RequestContext(request))
+    raw_post = ''
+    cleaned_data = ''
+    if request.POST:
+        raw_post = pprint.pformat(dict(request.POST))
+        if form.is_valid():
+            cleaned_data = pprint.pformat(getattr(form, 'cleaned_data', ''))
+
+    context = {
+        'cleaned_data': cleaned_data,
+        'form': form,
+        'raw_post': raw_post
+    }
+    return render_to_response('base.html', context, context_instance=RequestContext(request))
 
 
 def advanced(request):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.