ubernostrum / django-contact-form Goto Github PK
View Code? Open in Web Editor NEWA configurable contact-form application for Django.
Home Page: https://django-contact-form.readthedocs.io/
License: BSD 3-Clause "New" or "Revised" License
A configurable contact-form application for Django.
Home Page: https://django-contact-form.readthedocs.io/
License: BSD 3-Clause "New" or "Revised" License
Hi,
I have setup the django-contact-form in my project and works perfectly, nice job!
Now I want it to be directly embedded it on the homepage:
In the index template I have:
{% include 'contact_form/contact_form.html' %}
Which displays the contact-form correctly.
Who should I handle the POST request in my existing view?
Thanks,
Right now django-contact-form can't be installed along Django 3.1 because of the install_requires=["Django>=2.2,<3.1"]
dependency requirement: https://github.com/ubernostrum/django-contact-form/blob/master/setup.py#L37
Thanks
This seems to be the main problem on Django 1.11:
Traceback:
File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/exception.py" in inner
41. response = get_response(request)
File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py" in _get_response
187. response = self.process_exception_by_middleware(e, request)
File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py" in _get_response
185. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python3.5/dist-packages/django/views/generic/base.py" in view
68. return self.dispatch(request, *args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/django/views/generic/base.py" in dispatch
88. return handler(request, *args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/django/views/generic/edit.py" in post
183. return self.form_valid(form)
File "/usr/local/lib/python3.5/dist-packages/contact_form/views.py" in form_valid
18. form.save()
File "/usr/local/lib/python3.5/dist-packages/contact_form/forms.py" in save
132. send_mail(fail_silently=fail_silently, **self.get_message_dict())
File "/usr/local/lib/python3.5/dist-packages/contact_form/forms.py" in get_message_dict
124. message_dict[message_part] = attr() if callable(attr) else attr
File "/usr/local/lib/python3.5/dist-packages/contact_form/forms.py" in message
57. self.get_context())
File "/usr/local/lib/python3.5/dist-packages/django/template/loader.py" in render_to_string
68. return template.render(context, request)
File "/usr/local/lib/python3.5/dist-packages/django/template/backends/django.py" in render
64. context = make_context(context, request, autoescape=self.backend.engine.autoescape)
File "/usr/local/lib/python3.5/dist-packages/django/template/context.py" in make_context
287. raise TypeError('context must be a dict rather than %s.' % context.__class__.__name__)
Exception Type: TypeError at /contact/
Exception Value: context must be a dict rather than RequestContext.
Request information:
USER: AnonymousUser
My development settings contain the following directive so that email is printed to console instead of delivered via SMTP:
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
But after installing django-contact-form
1.4.2 and setting up as directed in the quick-start docs, submitting the contact form shows the success page but without any message printed to the console and with no errors shown anywhere. By contrast, using the exact same settings, user registration via django-registration produces the user account activation email message in the console, as expected.
As an additional test, I replaced the above setting with:
EMAIL_HOST = 'localhost'
EMAIL_PORT = '1025'
... and opened a separate terminal session to spawn an SMTP server via:
python -m smtpd -n -c DebuggingServer localhost:1025
... but submitting the contact form produces the same result: displays success page without delivering any mail and without displaying any errors.
Environment:
Contact form template:
{% extends "base.html" %}
{% load i18n %}
{% block content %}
<h3>{% trans "Contact Us" %}</h3>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">{% trans "Send Message" %}</button>
</form>
{% endblock %}
Perhaps I'm doing something irretrievably silly, but if so, I cannot fathom what that might be. What might I do to track down the source of the problem in order to resolve it?
django-simple-captcha is quite nice and easy to integrate.
I know Django 1.11 is not supported yet, but thought this might be helpful anyway.
Python 3.4.2 traceback:
File "/home/sbus/.virtualenvs/pro/lib/python3.4/site-packages/django/core/handlers/exception.py" in inner
41. response = get_response(request)
File "/home/sbus/.virtualenvs/pro/lib/python3.4/site-packages/django/core/handlers/base.py" in _get_response
187. response = self.process_exception_by_middleware(e, request)
File "/home/sbus/.virtualenvs/pro/lib/python3.4/site-packages/django/core/handlers/base.py" in _get_response
185. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/sbus/.virtualenvs/pro/lib/python3.4/site-packages/django/views/generic/base.py" in view
68. return self.dispatch(request, *args, **kwargs)
File "/home/sbus/.virtualenvs/pro/lib/python3.4/site-packages/django/views/generic/base.py" in dispatch
88. return handler(request, *args, **kwargs)
File "/home/sbus/.virtualenvs/pro/lib/python3.4/site-packages/django/views/generic/edit.py" in post
183. return self.form_valid(form)
File "/home/sbus/.virtualenvs/pro/lib/python3.4/site-packages/contact_form/views.py" in form_valid
18. form.save()
File "/home/sbus/.virtualenvs/pro/lib/python3.4/site-packages/contact_form/forms.py" in save
132. send_mail(fail_silently=fail_silently, **self.get_message_dict())
File "/home/sbus/.virtualenvs/pro/lib/python3.4/site-packages/contact_form/forms.py" in get_message_dict
124. message_dict[message_part] = attr() if callable(attr) else attr
File "/home/sbus/.virtualenvs/pro/lib/python3.4/site-packages/contact_form/forms.py" in message
57. self.get_context())
File "/home/sbus/.virtualenvs/pro/lib/python3.4/site-packages/django/template/loader.py" in render_to_string
68. return template.render(context, request)
File "/home/sbus/.virtualenvs/pro/lib/python3.4/site-packages/django/template/backends/django.py" in render
64. context = make_context(context, request, autoescape=self.backend.engine.autoescape)
File "/home/sbus/.virtualenvs/pro/lib/python3.4/site-packages/django/template/context.py" in make_context
287. raise TypeError('context must be a dict rather than %s.' % context.class.name)
Exception Type: TypeError at /contact/
Exception Value: context must be a dict rather than RequestContext.
Maybe related to this ticket? https://code.djangoproject.com/ticket/27722
How to add bcc and cc mail recipients in contact form ; (maybe a feature)
Django's send_mail
function doesn't allow for things like cc
, bcc
, and reply_to
. Being able to easily use those with django-contact-form
would be very nice. Currently, using those requires overriding the ContactForm
class' save
method. Although this change wouldn't be backwards compatible, I think it would be a good change.
I'm trying to follow the tutorial at http://atsoftware.de/2015/02/django-contact-form-full-tutorial-custom-example-in-django-1-7/ ; but I keep getting a NoReverseMatch
error. Any ideas what I'm doing wrong?
here is the error I'm getting: https://gist.github.com/tingletech/1f90d27c674ed978672e#file-error-txt
I added this to urls.py
https://gist.github.com/tingletech/1f90d27c674ed978672e#file-urls-py-diff
And this is my templates/contact_form
:
contact_form.html
{% extends 'calisphere/base.html' %}
{% block content %}
<form method="post">{% csrf_token %}
{% for field in form %}
<div class="fieldWrapper">
{{ field.errors }}
{{ field.label_tag }} {{ field }}
</div>
{% endfor %}
<input type="submit" value="Submit">
</form>
{% endblock %}
contact_form.txt
From: {{ name }} {{ email }}
Message: {{ reason }}
{{ body }}
contact_form_sent.html
<p>Message sent!</p>
contact_form_subject.txt
Contact form message
pip freeze | grep django-contact
django-contact-form==1.1
Here are my files:
settings.py
# Email settings
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'mypassword'
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
in urls.py:
url(r'^contact/', include('contact_form.urls')),
in contact_form.html:
{% extends "base.html" %}
{% load crispy_forms_tags %}
{% block title %}
{{ block.super }} | Contact
{% endblock title %}
{% block content %}
<h1>Contact me</h1>
<form action="" method="post">
{% csrf_token %}
{{ form|crispy }}
<input class='btn btn-primary' type="submit" value="Send" />
</form>
{% endblock content %}
in contact_form_sent.html:
{% extends "base.html" %}
{% block title %}
{{ block.super }} | Sent
{% endblock title %}
{% block content %}
<h1>Thank you</h1>
{% endblock content %}
in contact_form_subject.txt:
You've email from {{ name }}
in contact_form.txt:
{{ body}}
contact-form should test against Django 1.11b1. I didn't look deeply but you can't easily specify 1.11b1 in the Makefile based system:
1.11b1 tries to instal 1.11b1.0
1.11 tries to install 1.11.0
Both fail
I saw on the b-list.org blog that you were having some issues with tox and pyenv. I use pyenv and tox together without any issues or fiddling around with $PATH
. I think you need to have a .python-version
file in the project directory (or any parent directory) with contents like this:
3.3.6
3.6.0
3.5.3
3.4.6
2.7.12
In my case, I do not want the same person getting error messages and contact form messages. So, in my settings file, I set up a "CONTACT_EMAIL" tuple, then I changed this line in forms.py:
recipient_list = [mail_tuple[1] for mail_tuple in settings.MANAGERS]
to
recipient_list = [mail_tuple[1] for mail_tuple in settings.CONTACT_EMAIL]
I have installed the program fine.
I have trouble reading the quick start guide.
'contact_form'
to your setting.py/INSTALLED_APPS
contact_form.urls
is a from but I have no idea how to use it or from where to get it.contact_form.urls
goes in to the main application folder where the setting.py is?Thank you.
File "/data/www/.virtualenvs/muzeum_wejherowo_pl/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner
41. response = get_response(request)
File "/data/www/.virtualenvs/muzeum_wejherowo_pl/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
187. response = self.process_exception_by_middleware(e, request)
File "/data/www/.virtualenvs/muzeum_wejherowo_pl/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
185. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/data/www/.virtualenvs/muzeum_wejherowo_pl/lib/python3.6/site-packages/django/views/generic/base.py" in view
68. return self.dispatch(request, *args, **kwargs)
File "/data/www/.virtualenvs/muzeum_wejherowo_pl/lib/python3.6/site-packages/django/views/generic/base.py" in dispatch
88. return handler(request, *args, **kwargs)
File "/data/www/.virtualenvs/muzeum_wejherowo_pl/lib/python3.6/site-packages/django/views/generic/edit.py" in post
183. return self.form_valid(form)
File "/data/www/.virtualenvs/muzeum_wejherowo_pl/lib/python3.6/site-packages/contact_form/views.py" in form_valid
19. form.save()
File "/data/www/.virtualenvs/muzeum_wejherowo_pl/lib/python3.6/site-packages/contact_form/forms.py" in save
125. send_mail(fail_silently=fail_silently, **self.get_message_dict())
File "/data/www/.virtualenvs/muzeum_wejherowo_pl/lib/python3.6/site-packages/django/core/mail/__init__.py" in send_mail
62. return mail.send()
File "/data/www/.virtualenvs/muzeum_wejherowo_pl/lib/python3.6/site-packages/django/core/mail/message.py" in send
348. return self.get_connection(fail_silently).send_messages([self])
File "/data/www/.virtualenvs/muzeum_wejherowo_pl/lib/python3.6/site-packages/django/core/mail/backends/smtp.py" in send_messages
111. sent = self._send(message)
File "/data/www/.virtualenvs/muzeum_wejherowo_pl/lib/python3.6/site-packages/django/core/mail/backends/smtp.py" in _send
123. from_email = sanitize_address(email_message.from_email, encoding)
File "/data/www/.virtualenvs/muzeum_wejherowo_pl/lib/python3.6/site-packages/django/core/mail/message.py" in sanitize_address
161. address = Address(nm, addr_spec=addr)
File "/usr/lib/python3.6/email/headerregistry.py" in __init__
42. a_s, rest = parser.get_addr_spec(addr_spec)
File "/usr/lib/python3.6/email/_header_value_parser.py" in get_addr_spec
1583. token, value = get_local_part(value)
File "/usr/lib/python3.6/email/_header_value_parser.py" in get_local_part
1395. if value[0] in CFWS_LEADER:
sorry for this inadvertent add - will learn how to delete.
Context must be a dict rather than RequestContext.
Request Method: POST
Request URL: http://xxx.ca:8000/contact/
Django Version: 1.11b1
Exception Type: TypeError
Exception Value:
context must be a dict rather than RequestContext.
Exception Location: /home/xxx/py3env/lib/python3.5/site-packages/django/template/context.py in make_context, line 285
Python Executable: /home/xxx/py3env/bin/python
Python Version: 3.5.2
any ideas?
Django 2.0 is out, so it would be great to support it.
Any plans for a new PyPi release that supports Django 1.9?
Thanks for the well-documented & easily customized code!
6d66d3a is not a proper way to add a tag.
Hello,
I am using this package for the first time, the latest stable release (1.4.1) in a Django 1.9.13 project with Python 2.7.13. The first thing I did was try to use the package out of the box without any subclassing. However, I ran into an error that is traced back to the forms module trying to import Site from the Django sites framework:
from django.contrib.sites.models import Site
I do not have the sites framework installed in this project. The app is supposed to fallback to a RequestSite instance if the sites framework is not installed, but I am getting the following error:
RuntimeError: Model class django.contrib.sites.models.Site doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
As a test, I commented out the import line above as well as the check for the sites framework in the get_context method:
if Site._meta.installed:
site = Site.objects.get_current()
else:
site = RequestSite(self.request)
I replaced that part with the following simple line that assumes sites is not installed:
site = RequestSite(self.request)
This caused the app to work correctly. I will attempt to install the sites framework in my project to get this app working, but I just wanted to let you know about this issue in case you wanted to fix it to comply with the intent written in the documentation. Please let me know if I am incorrect.
Thanks,
Christopher Patterson
[email protected]
I'm starting to upgrade a project from Django 1.10 to 1.11 and the only blocker so far is django-contact-form. I cloned the django-contact-form repo and tested it against Django 1.11 and all tests pass. Would it be possible to cut a release that supports Django 1.11?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.