*#views.py* def check(request): if request.method == 'POST': form = UploadForm(request.POST, request.FILES) form.save() return HttpResponseRedirect("/") else: form = UploadForm() return render(request, 'upload.html', {'form': form})
def home(request): return render(request,'home.html') *#forms.py* class UploadForm(ModelForm): class Meta: model=Files fields=['file_name','files','subject','uploader_roll_no','uploader_email'] *#models.py* def get_file_path(instance,filename): return (settings.MEDIA_ROOT+'/'+instance.subject.departement_code+'/'+instance.subject.subject_code+'/'+filename) class Subject(models.Model): departement_code=models.CharField(max_length=2,blank=False) subject_code=models.CharField(max_length=7,blank=False) subject_name=models.CharField(max_length=100,blank=False) def __str__(self): return u'%s | %s' %(self.subject_code,self.subject_name) class Files(models.Model): file_name=models.CharField(max_length=100,blank=False) files=models.FileField(upload_to=get_file_path,blank=False) subject=models.ForeignKey(Subject,blank=False) verified=models.BooleanField(default=False,blank=False) uploader_roll_no=models.CharField(max_length=100,blank=False) uploader_email=models.EmailField(blank=False) def __str__(self): return (self.file_name) *#urls.py* urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^check/',check), url(r'^$',home) ] *#upload.html* <!DOCTYPE html> <html> <head> <title>Upload Files</title> <link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"> <link type="text/css" rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.98.2/css/materialize.min.css" media="screen,projection"/> <link type="text/css" rel="stylesheet" href="../static/style.css" media="screen,projection"/> <meta name="viewport" content="width=device-width, initial-scale=1.0"/> </head> <body> <div> <div class="row valign-wrapper"> <div id="name_form" class="centre card valign-wrapper center-block col s12 m8 offset-m2 container"> <h2 class="center-align card-action">Upload Files</h2> <div class="row"> <form class="col s12"> <div class="row"> <div class="container"> <form method="POST" action="" enctype="multipart/form-data"> {%csrf_token%} {{form.as_p}} <input type="submit" value="Upload"> </form> <div>{{ form.errors }}</div> </div> </div> </form> </div> </div> </div> </div> </body> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.98.2/js/materialize.min.js"></script> <script type="text/javascript" src="../static/anim.js"></script> <script> $(document).ready(function() { $('select').material_select(); }); </script> </html> Whenever i submit the data, the page reloads to itself and no data is saved. I am a beginner to django. Please help me -- 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 post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/1515d00f-8ba4-4e5b-a3bd-342d40a5bae1%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.