Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 553671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:37:47+00:00 2026-05-13T11:37:47+00:00

I’m writing a Django admin action to mass e-mail contacts. The action is defined

  • 0

I’m writing a Django admin action to mass e-mail contacts. The action is defined as follows:

def email_selected(self,request,queryset):
    rep_list = [] 
    for each in queryset:

        reps = CorporatePerson.objects.filter(company_id = Company.objects.get(name=each.name))

        contact_reps = reps.filter(is_contact=True)
        for rep in contact_reps:
            rep_list.append(rep)

    return email_form(request,queryset,rep_list)

email_form exists as a view and fills a template with this code:

def email_form(request,queryset,rep_list):
    if request.method == 'POST':
        form = EmailForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            send_mail(
                cd['subject'],
                cd['message'],
                cd.get('email','noreply@localboast'),['redacted@email.com'],
            )
            return HttpResponseRedirect('thanks')
        else:
            form = EmailForm()
        return render_to_response('corpware/admin/email-form.html',{'form':form,})

and the template exists as follows:

<body>
    <form action="/process_mail/" method="post">
        <table>
            {{ form.as_table }}
        </table>
        <input type = "submit" value = "Submit">
    </form>
</body>

/process_mail/ is hardlinked to another view in urls.py – which is a problem. I’d really like it so that I don’t have to use <form action="/process_mail/" method="post"> but unfortunately I can’t seem to POST the user inputs to the view handler without the admin interface for the model being reloaded in it’s place (When I hit the submit button with , the administration interface appears, which I don’t want.)

Is there a way that I could make the form POST to itself (<form action="" method="post">) so that I can handle inputs received in email_form? Trying to handle inputs with extraneous URLs and unneeded functions bothers me, as I’m hardcoding URLs to work with the code.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T11:37:47+00:00Added an answer on May 13, 2026 at 11:37 am

    You can use django’s inbuilt url tag to avoid hardcoding links. see…

    http://docs.djangoproject.com/en/dev/ref/templates/builtins/#url

    Chances are you’d be better off setting up a mass mailer to be triggered off by a cron job rather than on the post.

    Check out the answer I posted here
    Django scheduled jobs

    Also if you insist on triggering the email_send function on a view update perhaps look at

    http://docs.djangoproject.com/en/dev/topics/signals/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.