0

What would be the equivalent raw sql for the following:

def index:
    Emails.objects.create(email=request.POST['invite_email'])

I have this so far, but I can't quite get the quotations working --

    cursor = connection.cursor()
    cursor.execute("insert into splash_emails (id, email) values ('0','request.POST[invite_email]')")
    transaction.commit_unless_managed()

What would be correct way to write this, and is this the simplest way to perform raw sql?

0

2 Answers 2

2

If you ever want to see the queries django is using you can do:

emails = Emails.objects.create(email=request.POST['invite_email'])
print emails.query

It's a bit verbose, but you'll get the gist.

Sign up to request clarification or add additional context in comments.

Comments

2

I think after reading the Django cookbook chapter on Security, you'll have a good idea on how to execute raw sql AND execute it safely.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.