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 739971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:27:42+00:00 2026-05-14T08:27:42+00:00

I’ve recently begun working on Django and now my app is nearing completion and

  • 0

I’ve recently begun working on Django and now my app is nearing completion and i’ve begun to wonder about security and best-practices.

I have view that generates a page and different functions in the page post AJAX requests to individual views. For example, I have a view called show_employees and I can delete and update employees by passing an an post request to the views delete_employee and update_employee.

  1. I’ve put @login_required decorators before each of these views since I don’t want anyone accessing them without being authenticated. Is this okay?

  2. In the delete_employee and update_employee views, I only respond to request if it is an AJAX POST request (uisng is_ajax()). Is this okay?

  3. I return a ‘success’ when the view succeeds in doing what is needed and an error when there is a Validation error in my form but I’m still not handling other exceptions. How should I do this? Should i return standard 500 page through an AJAX response like this by wrapping the view with a try-except block to handle all exceptions?

  4. Is there anything else I can do secure my view?

Here’s a sample view of mine:

    @login_required
    def add_site(request):
        data = {}
        if request.method == 'POST':
            if request.is_ajax():
                form = AddSiteForm(request.user, request.POST)
                if form.is_valid():
                    site = form.save(commit=False)
                    site.user = request.user
                    site.save()
                    data['status'] = 'success'
                    data['html'] = render_to_string('site.html', locals(), context_instance=RequestContext(request))
                    return HttpResponse(simplejson.dumps(data), mimetype='application/json')
                else:
                    data['status'] = 'error'
                    data['errors'] = {}
                    for field, error in form.errors.iteritems():
                        data['errors']['id_'+field] = strip_tags(unicode(error))
                    return HttpResponse(simplejson.dumps(data), mimetype='application/json')

Thank you.

  • 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-14T08:27:42+00:00Added an answer on May 14, 2026 at 8:27 am

    Well, instead of only using @login_required, I suggest you take a look at the permissions framework and the associated permission required decorator. This way you can fine tune access restrictions on a user or group basis. It’s also easier and safer to change user behavior afterwards with permissions than with just a login_required decorator. Suppose now you have only admins, but later you want to add other kinds of users, it’s easy then to miss a login_required decorator then and granting those users access to admin views. You won’t have this problem with properly defined permissions.

    Next, is_ajax just checks for the HTTP_X_REQUESTED_WITH header. This has not really to do with security, but with user friendly behavior. This way you prevent a normal user from accidentally opening that page in the browser and getting some weird data. It does not help anything in security, every decent hacker can set an additional HTTP header :).

    Not handling exceptions can be potentially dangerous, if you accidentally leave on the DEBUG=True, in which case django will provide pieces of code and backtraces, potentially giving away weaknesses. But, if this option is off django will show it’s own 500 error page. My suggestion is: look for all expected django exceptions (aren’t that many) and make sure you catch those properly. Further I’d say, let the other exception be handled by django, django will still provide possibilities to generate backtraces and other debugging info and send these to the admins instead of displaying them on-site. If you catch all unexpected errors this behavior will not be directly available, maybe leaving you unknown about failing code.

    Finally, as you are working with user input data, I’d suggest you take a look at the security chapter in the django book, it explains the most important threats and how to handle them in the django framework.

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into

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.