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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:48:29+00:00 2026-06-03T08:48:29+00:00

I have an ajax view: def ajax_prices(request): data = {‘data’:’data’} return HttpResponse(json.dumps(data), mimetype=’application/json’) I

  • 0

I have an ajax view:

def ajax_prices(request):
    data = {'data':'data'}
    return HttpResponse(json.dumps(data), mimetype='application/json')

I want to test this with a local json file (prices.json). How can I import a local json file?

Local json file ‘prices.json’

{"aaData": [
[1, "70.1700", "2008-12-29 11:23:00"],
[2, "70.2600", "2008-12-29 16:22:00"],
[3, "70.6500", "2008-12-30 11:30:00"],
[4, "70.8700", "2008-12-30 16:10:00"],
[5, "70.5500", "2009-01-02 11:09:00"],
[6, "70.6400", "2009-01-02 16:15:00"],
[7, "70.6500", "2009-01-05 11:17:00"]
]}

I can’t do that with:

data = '/static/prices.json'
  • 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-06-03T08:48:30+00:00Added an answer on June 3, 2026 at 8:48 am

    Use the json module:

    import json
    
    json_data = open('/static/prices.json')   
    data1 = json.load(json_data) # deserialises it
    data2 = json.dumps(data1) # json formatted string
    
    json_data.close()
    

    See here for more info.

    As Joe has said, it’s a better practice to use fixtures or factories for your test data.

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

Sidebar

Related Questions

I have a simple view that I'm using to experiment with AJAX. def get_shifts_for_day(request,year,month,day):
I have a mvc2 application with a view like this <% using (Ajax.BeginForm(UserApprove, new
In an MVC3 application I have a view rendering two Ajax partial views: a
I have a view that allows to add tags dynamically with an ajax request.
I have a view helper, let say (for simplicity's sake) def call_alert return alert
I have a partial view which contain JavaScript and Ajax, but does not run
I have the following view definition in my asp.net mvc website: <% Using Ajax.BeginForm(UsrCtlChangePassword,
I'm having some difficulties with Ajax.BeginForm I have something like this in a view
I have ajax request that do 3 missions: Save Model (DB) Send Email Give
Currently I have a view which I render to a template and return it

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.