Super Sale Limited Time 50% OFF for All-Access Plans
Save 50% Now

Form implementation with Django


Hello,

I don't understand how implement a form with Metronic. (Signin for exemple).
Template is provided , but how does it configure wiews.py for get and post request?

I don't know how intregrate the code below inside wievs.py.


"""Connexion à la plateforme"""
class LoginPageView(View):
template_name = "authentication/login.html"
form_class = forms.LoginForm

def get(self, request):
form = self.form_class()
message = ""
return render(request, self.template_name, context={"form": form, "message": message})

def post(self, request):
form = self.form_class(request.POST)
if form.is_valid():
user = authenticate(
username=form.cleaned_data["username"],
password=form.cleaned_data["password"],
)
if user is not None:
login(request, user)
return redirect("home")
message = "Identifiants invalides."
return render(request, self.template_name, context={"form": form, "message": message})


"""Déconnexion de la plateforme"""
def logout_user(request):

logout(request)
return redirect("login")


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (2)


Hi,

No worry. Glad you have solved it.

Thanks



my fault !

I forgot to remove "//" in JS file : //submit.form() => submit.form()


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(