Image Uploading through form

Hi guys i have created a model name contact and successfully submit data through form into that model, but when i try to submit the image through form it submit successfully too,so far so good but when i try to open the image through admin dashboard by clicking the link it shows me 404 and the image didnt store in media folder. But when i submit the image through admin it follows the correct path and store in my media folder.


Can you post the view, form and template relevant to this problem?
Also, have you defined MEDIA_ROOT and MEDIA_URL in your `

Take a look at the documentation on handling uploaded files.

from django.shortcuts import render
from django.shortcuts import get_object_or_404, render
from django.http import HttpResponse
from web.models import Contact,NewsLetter
def home(request):
return render(request, ‘web/home.html’)

def contact(request):
if request.method == ‘POST’:
print(‘Data Entered’)
return render(request, ‘web/contact.html’)

def news(request):
if request.method == ‘POST’:
return render(request, ‘web/news.html’)

htm form

{% extends "web/base.html "%}
{% load static %}
{% block title %}
{% endblock title %}

{% block head %}

{% endblock %} {% block content %}
{% csrf_token %}
					  <div class="col-md-6">
						  <div class="form-group">
							  <input type="text" class="form-control" id="last_name" name="last_name" placeholder="Last Name" required data-error="Please enter your name">
							  <div class="help-block with-errors"></div>

					<div class="col-md-6">
						<div class="form-group">
							<input type="email" placeholder="Your Email" id="email" class="form-control" name="email" required data-error="Please enter your email">
							<div class="help-block with-errors"></div>
					<div class="col-md-6">
						<div class="form-group">
							<input type="phone" placeholder="Your number" id="phone" class="form-control" name="phone" required data-error="Please enter your number">
							<div class="help-block with-errors"></div>
					<div class="col-md-12">
						<div class="form-group"> 
							<textarea class="form-control" placeholder="Your Message" id="message" name="message" rows="8" data-error="Write your message" required></textarea>
							<div class="help-block with-errors"></div>
						<div class="col-md-4">
							<input type="file" name="mm" accept="application/pdf , image/jpeg">
						<div class="submit-button text-center">
							<button class="btn btn-common" id="submit" type="submit">Send Message</button>
							<div id="msgSubmit" class="h3 text-center hidden"></div> 
							<div class="clearfix"></div> 

{% endblock %}

from django.db import models
import datetime
from django.utils import timezone

Create your models here.

class Contact(models.Model):
image=models.FileField(null=True, blank=True, upload_to=‘images’)

def __str__(self):
	return self.first_name + " - " +

class NewsLetter(models.Model):

def __str__(self):
	return self.emailNL

Blockquote Yes i did define MEDIA_ROOT and MEDIA_URL in `

When you’re posting code, html, css here, please enclose it between lines of three backtick (`) characters to preserve the formatting of the code. This means you’ll have a line of ```, then however many lines of code, then another line of ```. Make sure you use the backtick - ` and not the apostrophe - '.

Also, you probably should be creating a Django form for doing this. Manually creating the fields in the HTML and assigning them in your view is doing a lot more work than necessary. You’re going to find it a lot easier to do this using a form.



oh sorry, did’nt know that.
And thank you sir i have created file and follow the guidelines from documentation and it worked fine.

No need to apologize - we’re here to share information. Glad to see you’ve got it working!