title: Python Django IMG upload function based
body: <p>I do not want to use class based forms. (function based)  I need to be able to created my own form with a few fields and give the option to add either a photo or word doc.  Any help would be awesome.</p>
  <pre><code>def addmessage(request):
      if request.POST: 
          Message.objects.create(
              name_of_msg = request.POST['name_of_msg'],
              message = request.POST['message'],
              photo = request.POST['photo'], 
              file = request.POST['file']
          )  
          return redirect('/home')          
  
  def addmessage(request):
      if request.POST: 
          Message.objects.create(
              name_of_msg = request.POST['name_of_msg'],
              message = request.POST['message'],
              photo = request.FILES['photo'], 
              file = request.FILES['file']
          )  
          return redirect('/home')
  
  def home(request): 
      context={ 
          'photos' : Message.objects.all()
      } 
      return render(request, 'home.html', context)         
  
  #to access it on the front end
  {% for photo in photos %}  
  {{photo.photo}}   
  {% endfor %}    
  
  &lt;h3&gt;Add a Message:&lt;/h3&gt;
  &lt;form action=&quot;/addmessage&quot; method=&quot;POST&quot;&gt;
      {% csrf_token %}
      &lt;input class=&quot;type=&quot; text&quot; name=&quot;name_of_msg&quot; placeholder=&quot;Message Name&quot;&gt;
      &lt;br&gt;
      &lt;input class=&quot;type=&quot; text&quot; name=&quot;message&quot; placeholder=&quot;Message&quot;&gt;
      &lt;br&gt;
      &lt;input type=&quot;file&quot; name=&quot;photo&quot; placeholder=&quot;Add Photo&quot;&gt;
      &lt;br&gt;
      &lt;input type=&quot;file&quot; name=&quot;file&quot; placeholder=&quot;Add a Doc&quot;&gt;
      &lt;br&gt;
      &lt;input type=&quot;submit&quot; value=&quot;Add It!&quot;&gt;
  &lt;/form&gt;
  &lt;/div&gt;
  </code></pre>