My webpage looks like the following:
When I press "Submit" button, the page is "redirected" to some different page. If I don't specify get_absolute_url
method in my models.py
, I will get ImproperlyConfigured
error. If I set where to redirect to in my models.py, upon clicking the Submit button, it will be directed to that page. What I don't understand is, how does only the Submit button redirected to whatever the link I set up on my models.py? Why clicking on the links on the sidebar doesn't redirect to it?
Why does get_absolute_url method acts only upon clicking Submit button, but not the others?
practice_add_well.html
<!DOCTYPE html>
{% extends "base.html" %}
{% block content %}
<h1>Test Page for BHA</h1>
<form method="POST">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" class='btn btn-primary' value="Submit">
</form>
{% endblock %}
models.py
from django.db import models
from django.urls import reverse
class WellInfo(models.Model):
name = models.CharField(max_length=100)
region_location = models.CharField(max_length=100)
spud_date = models.CharField(max_length=100)
well_bore = models.CharField(max_length=100)
rig_name = models.CharField(max_length=100)
status = models.CharField(max_length=100)
def get_absolute_url(self):
return reverse(# some link....)
views.py
from django.shortcuts import render
from django.views.generic import View, TemplateView, ListView, DetailView, CreateView, UpdateView, DeleteView
from . import models
class WellInfoCreateView(CreateView):
template_name = 'practice_add_well.html'
context_object_name = 'bha_inputs'
model = models.WellInfo
fields = '__all__'