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

  • Home
  • SEARCH
  • 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 3721254
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T05:29:35+00:00 2026-05-19T05:29:35+00:00

So I am pretty new to both Django and Javascript (I am using JQuery)

  • 0

So I am pretty new to both Django and Javascript (I am using JQuery) and I am wondering if I am doing a hack or if there are more slick ways to send client-side displayed database ids to the django server-side. Here is my process:

I have a dataTable (http://datatables.net) that I am displaying rows of data by using the bProcessing option to use AJAX to retrieve records from the database. The URL in my urls.py is something like:

url(r'^assets/activitylog/(?P<cid>.*)$', views.getActivityTable_ajax, name="activitylog_table"),

and my dataTable ajax-relavant code is something like:

"sAjaxSource": "/assets/activitylog/" + getIDFromHTML(),

where the javascript function getIDFromHTML() grabs <cid> that is used by the Django view is simply:

function getIDFromHTML(){
    // Simply return the text in the #release_id div element from the HTML
    return $("#release_id").html();
};

This is the part that seems “hacky” to me. I am inserting into my template code the database id that I am using in the datatables URL (with display:none in the css) just so I can pass it back to the view. Most of this is necessitated because one cannot use django template tags in the javascript code unless the code is embedded into the HTML itself, which I am not (and will not) do.

The only other thing that I have found is to change the URL to get rid of the parameter passed in to:

url(r'^assets/activitylog', views.getActivityTable_ajax, name="activitylog_table"),

and change the view code to:

def getActivityTable_ajax(request):
    """Returns the activity for a given pid from HTTP GET ajax reqest"""

    pid = int(urlparse.urlparse(request.META['HTTP_REFERER']).path.split('/')[-1])
    # rest of view code here...

since the id that I need is on the end of this referer url.

This way I don’t have to monkey around with embedding the hidden database id into the HTML and passing it back to via ajax the the table population view code.

Is it okay to use HTTP_REFERER in the request object in this manner? Am I going about this in the totally wrong way?

Thanks in advance!

  • 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-19T05:29:36+00:00Added an answer on May 19, 2026 at 5:29 am

    … one cannot use django template tags in the javascript code unless the code is embedded into the HTML itself …

    This is incorrect. Simply make the <script> tag point to something in your urlconf, then have the view set the Content-Type header appropriately for JavaScript and output it.

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

Sidebar

Related Questions

I'm pretty new to Jquery and Javascript and was am working on a project
I am pretty new to both Dreamweaver and Coldfusion, and I am having a
Pretty new to Perl so there may be a very obvious solution here. I'm
I am pretty new to image capturing using java. Which is better and easy
I'm using Linq2SQL and I'm pretty new to it. I've got a User table
I am pretty new to both php and SQL. I have a login page
I am pretty new to both php and mysql. I have a txt file
I'm pretty new to CakePHP and i'm running through both the Cake Book and
im pretty new to jQuery, and i dont know how to do that, and
Let me start by saying I'm pretty new to using interfaces. I'm writing a

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.