i am trying to create a course from my frontend using django form, everything seems fine but when i hit the create button it just refreshes the page without saving to database or throwing back any error, and that is not what i am expecting.
create-course.html
JavaScript
x
17
17
1
def create_course(request):
2
if request.method == "POST":
3
form = CreateCourse(request.POST, request.FILES)
4
if form.is_valid():
5
new_form = form.save(commit=False)
6
new_form.slug = slugify(new_form.course_title)
7
new_form.course_creator = request.user
8
new_form.save()
9
messages.success(request, f'Your Course Was Successfully Created, Now in Review')
10
return redirect('dashboard:dashboard')
11
else:
12
form = CreateCourse()
13
context = {
14
'form': form
15
}
16
return render(request, 'dashboard/create_course.html', context)
17
models.py
JavaScript
1
30
30
1
class Course(models.Model):
2
course_title = models.CharField(max_length=10000)
3
slug = models.SlugField(unique=True)
4
course_thumbnail = models.ImageField(upload_to=user_directory_path)
5
short_description = models.CharField(max_length=10000)
6
course_description = models.TextField()
7
price = models.IntegerField(default=0)
8
discount = models.IntegerField(default=0)
9
requirements = models.CharField(max_length=10000)
10
course_level = models.CharField(max_length=10000, choices=COURSE_LEVEL)
11
# course_rating = models.CharField(max_length=10000, choices=COURSE_RATING)
12
# course_rating = models.ForeignKey(CourseRating, on_delete=models.SET_NULL, null=True, blank=True)
13
course_language = models.CharField(max_length=10000, choices=COURSE_LANGUAGE)
14
# course_category = models.CharField(max_length=10000, choices=COURSE_CATEGORY)
15
course_category = models.ForeignKey(Category, on_delete=models.DO_NOTHING)
16
course_tag = models.ManyToManyField(Tag)
17
course_cost_status = models.CharField(max_length=10000, choices=COURSE_COST_STATUS, default="Free")
18
course_intro_video = models.FileField(upload_to=user_directory_path)
19
course_intro_video_url = models.URLField(default="https://")
20
course_intro_video_embedded = models.URLField(default="https://")
21
course_creator = models.ForeignKey(User, on_delete=models.CASCADE)
22
date_created = models.DateTimeField(auto_now_add=True, null=True)
23
course_duration = models.IntegerField(default=0)
24
course_publish_status = models.CharField(max_length=10000, choices=COURSE_PUBLISH_STATUS)
25
views = models.IntegerField(default=0)
26
likes = models.IntegerField(default=0)
27
featured = models.BooleanField(default=False)
28
digital = models.BooleanField(default=True)
29
best_seller = models.BooleanField(default=False)
30
forms.py
JavaScript
1
9
1
from course.models import Course
2
from django import forms
3
4
class CreateCourse(forms.ModelForm):
5
6
class Meta:
7
model = Course
8
exclude = ('slug', 'course_cost_status', 'course_creator', 'date_created', 'course_publish_status', 'views', 'likes', 'featured' , 'digital' , 'best_seller')
9
Advertisement
Answer
this was fixed by just uploading an image, but i wasnt seeing any error because i was not displaying the error in the create page
JavaScript
1
2
1
{{ form.errors }}
2