Coder Social home page Coder Social logo

ubernostrum / django-contact-form Goto Github PK

View Code? Open in Web Editor NEW
124.0 7.0 50.0 329 KB

A configurable contact-form application for Django.

Home Page: https://django-contact-form.readthedocs.io/

License: BSD 3-Clause "New" or "Revised" License

Python 99.86% HTML 0.14%
python django contact-form email

django-contact-form's Introduction

CI status image

This application provides extensible contact-form functionality for Django sites.

Full documentation for all functionality is included and is also available online.

django-contact-form's People

Contributors

caioariede avatar debdolph avatar doismellburning avatar gionniboy avatar jamesbeith avatar jladage avatar onanypoint avatar sk1p avatar tiktuk avatar timgraham avatar ubernostrum avatar urtzai avatar yurkobb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

django-contact-form's Issues

.

sorry for this inadvertent add - will learn how to delete.

Django 1.11 TypeError context must be a dict rather than RequestContext

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

Exception Value: context must be a dict rather than RequestContext on Django 1.11

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

Django 1.11b1 context must be a dict rather than RequestContext

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?

I don't receive email after send button

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}}

CFWS_LEADER error?

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:

Testing w/ tox

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

Embeded contact-form in homepage

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,

How about an option to configure the email that will receive the messages?

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]

Submitted contact form message not delivered

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:

  • Python 3.6.3
  • Django 1.11.8 (also tested with 1.11.7, just in case, but same result)

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?

Test against Django 1.11b1

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

Cut a release that supports Django 1.11?

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?

Implementation Issues

I have installed the program fine.
I have trouble reading the quick start guide.

  1. I have added the 'contact_form' to your setting.py/INSTALLED_APPS
  2. contact_form.urls is a from but I have no idea how to use it or from where to get it.
  3. Is this contact_form.urls goes in to the main application folder where the setting.py is?
  4. "You can include it wherever you like in your site’s URL configuration; for example, to have it live at the URL /contact/:" what is this URL is a new application and contact is a subfolder?
  5. "If you’ll be using a custom form class, you’ll need to manually set up your URLs so you can tell django-contact-form about your form class. For example" in what cases do I need this and
  6. I just want to set it up for 1 template on the main landing page, How can I do that?

Thank you.

Possible bug in forms.py

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]

NoReverseMatch

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

screen shot 2015-08-26 at 9 45 23 pm

screen shot 2015-08-26 at 9 46 31 pm

screen shot 2015-08-26 at 9 46 42 pm

pip freeze | grep django-contact
django-contact-form==1.1

Consider using EmailMessage instead of send_mail

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.