Method Not Allowed (POST): /contact/sent/
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I am getting this method not allowed(post), like I can't post my forms.what could I be doing wrong.I am new to django. Could my url.py be wrong or my form-id is incorrect that doesn't enable the posting of data.I have the forms.py here, not sure if that could be a problem to my problem
views.py
class ContactUsView(ContactFormView):
""" Contact Us Form View """
form_class = ContactUsForm
def get_success_url(self):
return reverse('messaging:contact_form_sent')
def clear_notification(request):
""" Clears the notification for a given user"""
Notifications.objects.filter(user=request.user).delete()
return redirect(reverse('accounts:dashboard', args=(request.user,)))
urls.py
urlpatterns = [
path(
'contact/',
views.ContactUsView.as_view(),
name='contact_form'),
path(
r'contact/sent/',
TemplateView.as_view(
template_name='contact_form/contact_form_sent.html'),
name='contact_form_sent'),
path(r'clear/', views.clear_notification, name='clear_notification'),
]
contact_form.html
<div class="row">
<form id='ContactUsForm' method='post' action=% url 'messaging:contact_form_sent' %><br>
% csrf_token %
<div class="col-md-6">
<div class="form-group">
% csrf_token %
<input type="text" class="form-control input-upper" id="fullname" placeholder="John Doe" name="fullname">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
% csrf_token %
<input type="email" class="form-control input-upper" id="email" placeholder="Email" name="email">
</div>
</div>
</div><br><br>
<div class="row">
<div class="col-md-6">
<div class="form-group">
% csrf_token %
<input type="text" class="form-control input-upper" id="subject" placeholder="Subject" name="subject">
</div>
</div>
</div><br>
<div class="row">
<div class="col-md-10">
<div class="form-group">
% csrf_token %
<textarea class="form-control input-upper" id="message" placeholder="Message" name="message"></textarea>
</div>
% csrf_token %
<button type="submit" class="btn btn-primary btn-send-contact" value="SUBMIT">SEND</button>
</div>
</div><br><br>
</form>
</div>
</div>
</div>
% endblock %
base-view
"""
"""
from django.views.generic.edit import FormView
from .forms import ContactForm
try:
from django.urls import reverse
except ImportError: # pragma: no cover
from django.core.urlresolvers import reverse # pragma: no cover
class ContactFormView(FormView):
form_class = ContactForm
recipient_list = None
template_name = 'contact_form/contact_form.html'
def form_valid(self, form):
form.save()
return super(ContactFormView, self).form_valid(form)
def get_form_kwargs(self):
# ContactForm instances require instantiation with an
# HttpRequest.
kwargs = super(ContactFormView, self).get_form_kwargs()
kwargs.update('request': self.request)
# We may also have been given a recipient list when
# instantiated.
if self.recipient_list is not None:
kwargs.update('recipient_list': self.recipient_list)
return kwargs
def get_success_url(self):
return reverse('contact_form_sent')
django django-forms django-urls
add a comment |
I am getting this method not allowed(post), like I can't post my forms.what could I be doing wrong.I am new to django. Could my url.py be wrong or my form-id is incorrect that doesn't enable the posting of data.I have the forms.py here, not sure if that could be a problem to my problem
views.py
class ContactUsView(ContactFormView):
""" Contact Us Form View """
form_class = ContactUsForm
def get_success_url(self):
return reverse('messaging:contact_form_sent')
def clear_notification(request):
""" Clears the notification for a given user"""
Notifications.objects.filter(user=request.user).delete()
return redirect(reverse('accounts:dashboard', args=(request.user,)))
urls.py
urlpatterns = [
path(
'contact/',
views.ContactUsView.as_view(),
name='contact_form'),
path(
r'contact/sent/',
TemplateView.as_view(
template_name='contact_form/contact_form_sent.html'),
name='contact_form_sent'),
path(r'clear/', views.clear_notification, name='clear_notification'),
]
contact_form.html
<div class="row">
<form id='ContactUsForm' method='post' action=% url 'messaging:contact_form_sent' %><br>
% csrf_token %
<div class="col-md-6">
<div class="form-group">
% csrf_token %
<input type="text" class="form-control input-upper" id="fullname" placeholder="John Doe" name="fullname">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
% csrf_token %
<input type="email" class="form-control input-upper" id="email" placeholder="Email" name="email">
</div>
</div>
</div><br><br>
<div class="row">
<div class="col-md-6">
<div class="form-group">
% csrf_token %
<input type="text" class="form-control input-upper" id="subject" placeholder="Subject" name="subject">
</div>
</div>
</div><br>
<div class="row">
<div class="col-md-10">
<div class="form-group">
% csrf_token %
<textarea class="form-control input-upper" id="message" placeholder="Message" name="message"></textarea>
</div>
% csrf_token %
<button type="submit" class="btn btn-primary btn-send-contact" value="SUBMIT">SEND</button>
</div>
</div><br><br>
</form>
</div>
</div>
</div>
% endblock %
base-view
"""
"""
from django.views.generic.edit import FormView
from .forms import ContactForm
try:
from django.urls import reverse
except ImportError: # pragma: no cover
from django.core.urlresolvers import reverse # pragma: no cover
class ContactFormView(FormView):
form_class = ContactForm
recipient_list = None
template_name = 'contact_form/contact_form.html'
def form_valid(self, form):
form.save()
return super(ContactFormView, self).form_valid(form)
def get_form_kwargs(self):
# ContactForm instances require instantiation with an
# HttpRequest.
kwargs = super(ContactFormView, self).get_form_kwargs()
kwargs.update('request': self.request)
# We may also have been given a recipient list when
# instantiated.
if self.recipient_list is not None:
kwargs.update('recipient_list': self.recipient_list)
return kwargs
def get_success_url(self):
return reverse('contact_form_sent')
django django-forms django-urls
add a comment |
I am getting this method not allowed(post), like I can't post my forms.what could I be doing wrong.I am new to django. Could my url.py be wrong or my form-id is incorrect that doesn't enable the posting of data.I have the forms.py here, not sure if that could be a problem to my problem
views.py
class ContactUsView(ContactFormView):
""" Contact Us Form View """
form_class = ContactUsForm
def get_success_url(self):
return reverse('messaging:contact_form_sent')
def clear_notification(request):
""" Clears the notification for a given user"""
Notifications.objects.filter(user=request.user).delete()
return redirect(reverse('accounts:dashboard', args=(request.user,)))
urls.py
urlpatterns = [
path(
'contact/',
views.ContactUsView.as_view(),
name='contact_form'),
path(
r'contact/sent/',
TemplateView.as_view(
template_name='contact_form/contact_form_sent.html'),
name='contact_form_sent'),
path(r'clear/', views.clear_notification, name='clear_notification'),
]
contact_form.html
<div class="row">
<form id='ContactUsForm' method='post' action=% url 'messaging:contact_form_sent' %><br>
% csrf_token %
<div class="col-md-6">
<div class="form-group">
% csrf_token %
<input type="text" class="form-control input-upper" id="fullname" placeholder="John Doe" name="fullname">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
% csrf_token %
<input type="email" class="form-control input-upper" id="email" placeholder="Email" name="email">
</div>
</div>
</div><br><br>
<div class="row">
<div class="col-md-6">
<div class="form-group">
% csrf_token %
<input type="text" class="form-control input-upper" id="subject" placeholder="Subject" name="subject">
</div>
</div>
</div><br>
<div class="row">
<div class="col-md-10">
<div class="form-group">
% csrf_token %
<textarea class="form-control input-upper" id="message" placeholder="Message" name="message"></textarea>
</div>
% csrf_token %
<button type="submit" class="btn btn-primary btn-send-contact" value="SUBMIT">SEND</button>
</div>
</div><br><br>
</form>
</div>
</div>
</div>
% endblock %
base-view
"""
"""
from django.views.generic.edit import FormView
from .forms import ContactForm
try:
from django.urls import reverse
except ImportError: # pragma: no cover
from django.core.urlresolvers import reverse # pragma: no cover
class ContactFormView(FormView):
form_class = ContactForm
recipient_list = None
template_name = 'contact_form/contact_form.html'
def form_valid(self, form):
form.save()
return super(ContactFormView, self).form_valid(form)
def get_form_kwargs(self):
# ContactForm instances require instantiation with an
# HttpRequest.
kwargs = super(ContactFormView, self).get_form_kwargs()
kwargs.update('request': self.request)
# We may also have been given a recipient list when
# instantiated.
if self.recipient_list is not None:
kwargs.update('recipient_list': self.recipient_list)
return kwargs
def get_success_url(self):
return reverse('contact_form_sent')
django django-forms django-urls
I am getting this method not allowed(post), like I can't post my forms.what could I be doing wrong.I am new to django. Could my url.py be wrong or my form-id is incorrect that doesn't enable the posting of data.I have the forms.py here, not sure if that could be a problem to my problem
views.py
class ContactUsView(ContactFormView):
""" Contact Us Form View """
form_class = ContactUsForm
def get_success_url(self):
return reverse('messaging:contact_form_sent')
def clear_notification(request):
""" Clears the notification for a given user"""
Notifications.objects.filter(user=request.user).delete()
return redirect(reverse('accounts:dashboard', args=(request.user,)))
urls.py
urlpatterns = [
path(
'contact/',
views.ContactUsView.as_view(),
name='contact_form'),
path(
r'contact/sent/',
TemplateView.as_view(
template_name='contact_form/contact_form_sent.html'),
name='contact_form_sent'),
path(r'clear/', views.clear_notification, name='clear_notification'),
]
contact_form.html
<div class="row">
<form id='ContactUsForm' method='post' action=% url 'messaging:contact_form_sent' %><br>
% csrf_token %
<div class="col-md-6">
<div class="form-group">
% csrf_token %
<input type="text" class="form-control input-upper" id="fullname" placeholder="John Doe" name="fullname">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
% csrf_token %
<input type="email" class="form-control input-upper" id="email" placeholder="Email" name="email">
</div>
</div>
</div><br><br>
<div class="row">
<div class="col-md-6">
<div class="form-group">
% csrf_token %
<input type="text" class="form-control input-upper" id="subject" placeholder="Subject" name="subject">
</div>
</div>
</div><br>
<div class="row">
<div class="col-md-10">
<div class="form-group">
% csrf_token %
<textarea class="form-control input-upper" id="message" placeholder="Message" name="message"></textarea>
</div>
% csrf_token %
<button type="submit" class="btn btn-primary btn-send-contact" value="SUBMIT">SEND</button>
</div>
</div><br><br>
</form>
</div>
</div>
</div>
% endblock %
base-view
"""
"""
from django.views.generic.edit import FormView
from .forms import ContactForm
try:
from django.urls import reverse
except ImportError: # pragma: no cover
from django.core.urlresolvers import reverse # pragma: no cover
class ContactFormView(FormView):
form_class = ContactForm
recipient_list = None
template_name = 'contact_form/contact_form.html'
def form_valid(self, form):
form.save()
return super(ContactFormView, self).form_valid(form)
def get_form_kwargs(self):
# ContactForm instances require instantiation with an
# HttpRequest.
kwargs = super(ContactFormView, self).get_form_kwargs()
kwargs.update('request': self.request)
# We may also have been given a recipient list when
# instantiated.
if self.recipient_list is not None:
kwargs.update('recipient_list': self.recipient_list)
return kwargs
def get_success_url(self):
return reverse('contact_form_sent')
django django-forms django-urls
django django-forms django-urls
edited Nov 16 '18 at 14:29
user9504424
asked Nov 15 '18 at 16:02
user9504424user9504424
13
13
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
By default TemplateView
not allowing POST
, what you need to do is just overwrite the post method.
Exemple :
class ContactUsView(TemplateView):
template_name = 'contact_form/contact_form_sent.html'
def post(self, request, *args, **kwargs):
context = self.get_context_data()
if context["form"].is_valid():
print 'POST IS HERE'
return super(TemplateView, self).render_to_response(context)
def get_context_data(self, **kwargs):
context = super(ContactUsView, self).get_context_data(**kwargs)
form = ContactUsEmailForm(self.request.POST or None)
context["form"] = form
return context
I still get this error of "POST /contact/sent/ HTTP/1.1" 405 0 HTTP ERROR 405
– user9504424
Nov 16 '18 at 11:20
add a comment |
Your form is posting directly to the confirmation page, contact_form_sent, which is not expecting a post. By doing this it's bypassing the view that is actually processing the post, ContactUsView.
Your form action should be to messaging:contact_form
.
When I used that as action messaging:contact_form it returns me back to that same page to fill the contact form.
– user9504424
Nov 16 '18 at 11:13
Well, where is the processing of the form carried out? What is ContactFormView?
– Daniel Roseman
Nov 16 '18 at 11:37
I have added the forms.py
– user9504424
Nov 16 '18 at 13:18
I didn't ask for that, I asked for the base view class, ContactFormView.
– Daniel Roseman
Nov 16 '18 at 13:20
posted what i think you might be referring to
– user9504424
Nov 16 '18 at 15:35
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53323372%2fmethod-not-allowed-post-contact-sent%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
By default TemplateView
not allowing POST
, what you need to do is just overwrite the post method.
Exemple :
class ContactUsView(TemplateView):
template_name = 'contact_form/contact_form_sent.html'
def post(self, request, *args, **kwargs):
context = self.get_context_data()
if context["form"].is_valid():
print 'POST IS HERE'
return super(TemplateView, self).render_to_response(context)
def get_context_data(self, **kwargs):
context = super(ContactUsView, self).get_context_data(**kwargs)
form = ContactUsEmailForm(self.request.POST or None)
context["form"] = form
return context
I still get this error of "POST /contact/sent/ HTTP/1.1" 405 0 HTTP ERROR 405
– user9504424
Nov 16 '18 at 11:20
add a comment |
By default TemplateView
not allowing POST
, what you need to do is just overwrite the post method.
Exemple :
class ContactUsView(TemplateView):
template_name = 'contact_form/contact_form_sent.html'
def post(self, request, *args, **kwargs):
context = self.get_context_data()
if context["form"].is_valid():
print 'POST IS HERE'
return super(TemplateView, self).render_to_response(context)
def get_context_data(self, **kwargs):
context = super(ContactUsView, self).get_context_data(**kwargs)
form = ContactUsEmailForm(self.request.POST or None)
context["form"] = form
return context
I still get this error of "POST /contact/sent/ HTTP/1.1" 405 0 HTTP ERROR 405
– user9504424
Nov 16 '18 at 11:20
add a comment |
By default TemplateView
not allowing POST
, what you need to do is just overwrite the post method.
Exemple :
class ContactUsView(TemplateView):
template_name = 'contact_form/contact_form_sent.html'
def post(self, request, *args, **kwargs):
context = self.get_context_data()
if context["form"].is_valid():
print 'POST IS HERE'
return super(TemplateView, self).render_to_response(context)
def get_context_data(self, **kwargs):
context = super(ContactUsView, self).get_context_data(**kwargs)
form = ContactUsEmailForm(self.request.POST or None)
context["form"] = form
return context
By default TemplateView
not allowing POST
, what you need to do is just overwrite the post method.
Exemple :
class ContactUsView(TemplateView):
template_name = 'contact_form/contact_form_sent.html'
def post(self, request, *args, **kwargs):
context = self.get_context_data()
if context["form"].is_valid():
print 'POST IS HERE'
return super(TemplateView, self).render_to_response(context)
def get_context_data(self, **kwargs):
context = super(ContactUsView, self).get_context_data(**kwargs)
form = ContactUsEmailForm(self.request.POST or None)
context["form"] = form
return context
answered Nov 15 '18 at 17:17
MaximeKMaximeK
1,0561510
1,0561510
I still get this error of "POST /contact/sent/ HTTP/1.1" 405 0 HTTP ERROR 405
– user9504424
Nov 16 '18 at 11:20
add a comment |
I still get this error of "POST /contact/sent/ HTTP/1.1" 405 0 HTTP ERROR 405
– user9504424
Nov 16 '18 at 11:20
I still get this error of "POST /contact/sent/ HTTP/1.1" 405 0 HTTP ERROR 405
– user9504424
Nov 16 '18 at 11:20
I still get this error of "POST /contact/sent/ HTTP/1.1" 405 0 HTTP ERROR 405
– user9504424
Nov 16 '18 at 11:20
add a comment |
Your form is posting directly to the confirmation page, contact_form_sent, which is not expecting a post. By doing this it's bypassing the view that is actually processing the post, ContactUsView.
Your form action should be to messaging:contact_form
.
When I used that as action messaging:contact_form it returns me back to that same page to fill the contact form.
– user9504424
Nov 16 '18 at 11:13
Well, where is the processing of the form carried out? What is ContactFormView?
– Daniel Roseman
Nov 16 '18 at 11:37
I have added the forms.py
– user9504424
Nov 16 '18 at 13:18
I didn't ask for that, I asked for the base view class, ContactFormView.
– Daniel Roseman
Nov 16 '18 at 13:20
posted what i think you might be referring to
– user9504424
Nov 16 '18 at 15:35
add a comment |
Your form is posting directly to the confirmation page, contact_form_sent, which is not expecting a post. By doing this it's bypassing the view that is actually processing the post, ContactUsView.
Your form action should be to messaging:contact_form
.
When I used that as action messaging:contact_form it returns me back to that same page to fill the contact form.
– user9504424
Nov 16 '18 at 11:13
Well, where is the processing of the form carried out? What is ContactFormView?
– Daniel Roseman
Nov 16 '18 at 11:37
I have added the forms.py
– user9504424
Nov 16 '18 at 13:18
I didn't ask for that, I asked for the base view class, ContactFormView.
– Daniel Roseman
Nov 16 '18 at 13:20
posted what i think you might be referring to
– user9504424
Nov 16 '18 at 15:35
add a comment |
Your form is posting directly to the confirmation page, contact_form_sent, which is not expecting a post. By doing this it's bypassing the view that is actually processing the post, ContactUsView.
Your form action should be to messaging:contact_form
.
Your form is posting directly to the confirmation page, contact_form_sent, which is not expecting a post. By doing this it's bypassing the view that is actually processing the post, ContactUsView.
Your form action should be to messaging:contact_form
.
answered Nov 15 '18 at 17:49
Daniel RosemanDaniel Roseman
461k42597655
461k42597655
When I used that as action messaging:contact_form it returns me back to that same page to fill the contact form.
– user9504424
Nov 16 '18 at 11:13
Well, where is the processing of the form carried out? What is ContactFormView?
– Daniel Roseman
Nov 16 '18 at 11:37
I have added the forms.py
– user9504424
Nov 16 '18 at 13:18
I didn't ask for that, I asked for the base view class, ContactFormView.
– Daniel Roseman
Nov 16 '18 at 13:20
posted what i think you might be referring to
– user9504424
Nov 16 '18 at 15:35
add a comment |
When I used that as action messaging:contact_form it returns me back to that same page to fill the contact form.
– user9504424
Nov 16 '18 at 11:13
Well, where is the processing of the form carried out? What is ContactFormView?
– Daniel Roseman
Nov 16 '18 at 11:37
I have added the forms.py
– user9504424
Nov 16 '18 at 13:18
I didn't ask for that, I asked for the base view class, ContactFormView.
– Daniel Roseman
Nov 16 '18 at 13:20
posted what i think you might be referring to
– user9504424
Nov 16 '18 at 15:35
When I used that as action messaging:contact_form it returns me back to that same page to fill the contact form.
– user9504424
Nov 16 '18 at 11:13
When I used that as action messaging:contact_form it returns me back to that same page to fill the contact form.
– user9504424
Nov 16 '18 at 11:13
Well, where is the processing of the form carried out? What is ContactFormView?
– Daniel Roseman
Nov 16 '18 at 11:37
Well, where is the processing of the form carried out? What is ContactFormView?
– Daniel Roseman
Nov 16 '18 at 11:37
I have added the forms.py
– user9504424
Nov 16 '18 at 13:18
I have added the forms.py
– user9504424
Nov 16 '18 at 13:18
I didn't ask for that, I asked for the base view class, ContactFormView.
– Daniel Roseman
Nov 16 '18 at 13:20
I didn't ask for that, I asked for the base view class, ContactFormView.
– Daniel Roseman
Nov 16 '18 at 13:20
posted what i think you might be referring to
– user9504424
Nov 16 '18 at 15:35
posted what i think you might be referring to
– user9504424
Nov 16 '18 at 15:35
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53323372%2fmethod-not-allowed-post-contact-sent%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown