How it works...

In the js_settings view, we built a dictionary of settings that we want to pass to the browser, converted the dictionary to JSON, and rendered a template for a JavaScript file that parses the JSON and assigns the result to the window.settings variable. By converting a dictionary to a JSON string and parsing it in the JavaScript file, we can be sure that we won't have any problems with trailing commas after the last element—that's allowed in Python, but invalid in JavaScript.

The rendered JavaScript file will look like this:

# http://127.0.0.1:8000/en/js-settings/
window.settings = JSON.parse(
'{u0022MEDIA_URLu0022: u0022http://127.0.0.1:8000/media/u0022, u0022STATIC_URLu0022: u0022/static/20191001004640/u0022, u0022DEBUGu0022: true, u0022LANGUAGESu0022: [[u0022bgu0022, u0022Bulgarianu0022], [u0022hru0022, u0022Croatianu0022], [u0022csu0022, u0022Czechu0022], [u0022dau0022, u0022Danishu0022], [u0022nlu0022, u0022Dutchu0022], [u0022enu0022, u0022Englishu0022], [u0022etu0022, u0022Estonianu0022], [u0022fiu0022, u0022Finnishu0022], [u0022fru0022, u0022Frenchu0022], [u0022deu0022, u0022Germanu0022], [u0022elu0022, u0022Greeku0022], [u0022huu0022, u0022Hungarianu0022], [u0022gau0022, u0022Irishu0022], [u0022itu0022, u0022Italianu0022], [u0022lvu0022, u0022Latvianu0022], [u0022ltu0022, u0022Lithuanianu0022], [u0022mtu0022, u0022Malteseu0022], [u0022plu0022, u0022Polishu0022], [u0022ptu0022, u0022Portugueseu0022], [u0022rou0022, u0022Romanianu0022], [u0022sku0022, u0022Slovaku0022], [u0022slu0022, u0022Sloveneu0022], [u0022esu0022, u0022Spanishu0022], [u0022svu0022, u0022Swedishu0022]], u0022DEFAULT_LANGUAGE_CODEu0022: u0022enu0022, u0022CURRENT_LANGUAGE_CODEu0022: u0022enu0022}');
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.37.68