When we submit a form, what happened?
<p>Actually, I just want to get a very simple web application:</p>

<ol>
<li>a form in a webpage that I can upload a file within some parameters;</li>
<li>submit the form when I choose a proper file;</li>
<li>do some calculation using these parameters in uploaded file;</li>
<li>redirect to a new webpage with the calculation result;</li>
<li>display the result in this new webpage.</li>
</ol>

<p>I use Django 1.10. </p>

<p><strong>index.html</strong> with <code>&lt;form&gt;</code> like this:</p>

<pre><code>&lt;form action="/index/result/" method="post" enctype="multipart/form-data"&gt;
    {% csrf_token %}
    &lt;input type="&gt;
    &lt;div class="field"&gt;
        &lt;label for="id_file"&gt;Input File:&lt;/label&gt;
        {{ form.file }}  &lt;!--from django model--&gt;
    &lt;/div&gt;
    &lt;p&gt;&lt;input type="submit" value="Submit"/&gt;&lt;/p&gt;
&lt;/form&gt;
</code></pre>

<p><strong>result.html</strong> for display result like this:</p>

<pre><code>&lt;div id="out"&gt;
    &lt;table id="result_display" border="1px" hidden&gt;
        &lt;thead&gt;
            &lt;tr&gt;
                &lt;th&gt;No.&lt;/th&gt;
                &lt;th&gt;Name&lt;/th&gt;
            &lt;/tr&gt;
        &lt;/thead&gt;
        &lt;tbody&gt;
            &lt;tr&gt;
                &lt;th&gt;1&lt;/th&gt;
          &lt;!--here will display the value comes from result--&gt;
                &lt;th id="r_name"&gt; {{ result }} &lt;/th&gt;
            &lt;/tr&gt;
        &lt;/tbody&gt;
    &lt;/table&gt;
&lt;/div&gt;
</code></pre>

<p>my <strong>views.py</strong> like this:</p>

<pre><code>from django.http import HttpResponse
from django.shortcuts import render, redirect
from django.views.decorators.csrf import csrf_exempt
from forms import UploadFileForm


# Create your views here.
@csrf_exempt
def index_view(request):
    para = ''
    if request.method == 'POST':
        form = UploadFileForm(request.POST, request.FILES)
        if form.is_valid():
            cd = form.cleaned_data
            if cd['file']:
                para = cd.get('file').read().split('\r\n')
            else:
                return HttpResponse('Please Input a File!')
        else:
            return HttpResponse('Form is invalid!')
    if para:
        # do some calculation with para
        result = {"name": "NAD"}
        return redirect('result_view', result=result)  # to another view 'result_view'
    else:
        form = UploadFileForm()
    return render(request, 'index.html', {'form': form})


def result_view(request, result=''):
    if result:
        return render(request, 'result.html', {'result': result})
    else:
        return HttpResponse('no result!')
</code></pre>

<p>my <strong>urls.py</strong> like this:</p>

<pre><code>from django.conf.urls import url, include
from django.contrib import admin
admin.autodiscover()
urlpatterns = [
    url(r'^index/$', index_view),
    url(r'^index/result/?(?P&lt;result&gt;.*)/$', result_view, name='result_view'),
]
</code></pre>

<p>Here are what really confuse me a lot:</p>

<p><strong>Q1</strong>: There are two places give result url address <code>&lt;form action="/index/result/" method="post" enctype="multipart/form-data"&gt;</code> in index.html and <code>url(r'^index/result/?(?P&lt;result&gt;.*)/$', result, name='result'),</code> in urls.py, which one is dominated?</p>

<p><strong>Q2</strong>: How to pass data (i.e. calculation result) from <code>index_view</code> to <code>result_view</code>? 
I didn't get <code>result</code> in <code>result_view</code> function using current method.</p>

<p>Q1: urls.py only maps the urls to the views used to render them. When you submit a form to <code>/index/result/</code>, Django will try to find a view, that matches the url, in this case <code>results_view</code>.</p>

<p>Q2: Instead of passing the result from <code>index_view</code> to <code>result_view</code>, you should move the whole logic of calculating the result to the <code>result_view</code>.</p>

python django