Django Chinese-style static files (css, javascript)
Using css, Javascript in Django templates Test environment (r’^css/(?P.*)$’, ‘django.views.static.serve’, {‘document_root’: ‘/var/www/django-demo/css ‘}),(r’^js/(?P.*)$’, ‘django.views.static.serve’, {‘document_root’: ‘/var/www/ django-demo/js’}),(r’^images/(?P.*)$’, ‘django.views.static.serve’, {‘document_root’: ‘ /var/www/django-demo/images’}), Use the following method in the template: Note: os. path.dirname(globals()[“__file__”]) to get the path of the current file, such as (r’^css/(?P.*)$’, ‘django.views .static.serve’, {‘document_root’: os.path.dirname(globals()[“__file__”])+’/css’}), You can use os.path.abspath() The function returns the absolute path of this path. ============== To reference static files such as css, js, gif, etc. in django’s template file, first create a setting.py The DEBUG switch is turned on. 1. Create a directory to store static files in the project directory, such as: medias2. Add a line to url.py patterns: (r’^site_media/(?P. *)$’,’django.views.static.serve’,{‘document_root’:settings.STATIC_PATH}), Also from django.conf import setting3. Add a line to setting.py: STATIC_PATH=’./medias’ After setting this, you can reference the static files stored in media in the template file, such as: Online environment The use of css cannot be avoided in web projects developed with Django , Javascript, js and other static files. As for the processing of these static files, Django’s official website writes: Django itself doesn’t serve static (media) files, such as images, style sheets, or video. It leaves that job to whichever Web server you choose. That is to say, Django itself…
JavaScript
Cross-platform, operated on the client Writing location Event-driven Java Script Common events Demo Java Script events
javaScript, PHP connection to takeaway ticket machine printer solution (calling Jiabo, Xinye, etc.)
Foreword: Current development requires a computer to directly connect to a takeout receipt machine to print receipts and access various information. Using HttpPrinter finally solved this problem. Effect: PHP and Javascript directly connect to the ticket machine and automatically issue tickets. Supported small ticket machines: The ones currently tested include: computer A4 printer, Jiabo GP58MBIII (USB direct connection), Xinye xp-58IIL (USB). In principle, it can support all USB-connected ticket machines. The current template is set according to 58MM. // Print POS Ticket Begin Function Print (ARR) { var ip = $ (“#ip”). Val (); VAR PORT = $(“#port”).val(); if(ip==””||port==””){alert(“ip,port cannot be empty”); return false;}<br /// Treatment of food data var Foodsjson = & # 39; & # 39; for (var I = 0; i { Foodsjson = Foodsjsjson + & # 39; {“” shangpname”:'+arr.foods[i].name +',”shuliang”:'+ arr.foods[i].count+', “je”:& #39;+ arr.foods[i].price+'},'; } var msg = '{' '”method”:”' + 'printreport' +'”' /*Report type gridreport fastreport reportmachine If empty, it will default to gridreport */ +',”ReportType”:”' + 'fastreport' +'”' /*Report type gridreport fastreport reportmachine If empty, it will default to gridreport */ +& # 39;, “Reportname”: “& # 39; +& # 39; AAALQS.FR3 &…
Web basic knowledge points (html, css, http, javaScript)
1.htmlBasic Knowledge HTML is not a programming language, but a markup language used to tell the browser how to organize a page. 1. Element The start tag + content + end tag is a complete element. But empty elements only have start tags. For example: the element is used to insert a specified picture at the location of the element . 2. Nested elements Elements can be placed within other elements – this is called nesting set. For example: I love my Motherland The tag is used here to emphasize the content of the motherland. 3. Introduction to common elements (1.) Title to (2.) Paragraph (3.) List List with serial number: List without serial number: (4.) Hyperlink (5.) Image (6.) Block-level semantic element None Semantic elements are usually used to organize content so that it can be laid out or manipulated through CSS or JS later. (7.) Inline semantic-less elements 4. Document structure 5.htmlComments 2.css basic knowledge Full name: CascadingStyleSheets->Cascading Style Sheets Definition: CSS becomes a cascading style sheet, which is mainly used to set the text content (font, size, alignment, etc.), the shape of the image (width and height, border style, margins, etc.) in the HTML page, and The…
javascript, php code to obtain function parameter object
For example: The code is as follows: function say () { alert (arguments[0]+’say:’+arguments[1]) ; } say (‘fanglor’,’fanglor is a boy!’); Result: pop up fanglor saying: fanglor is a boy! ——- ————————————————– ———————– This is somewhat similar to the func_get_args() function in PHP, which also obtains an array of function parameters. Example (the following is php code): The code is as follows: function uses () { $args =func_get_args(); if (!empty($args)) { foreach ($args as $key => $val ) { if (file_exists($val.’.php’)) { include ” {$val}.php”; } else { if (DEBUG) { echo “{$val}.php does not exist!”; } } } } } //Encapsulate include again uses (‘config’,’db’); Automatically load config.php and db.php, if they do not exist, It shows that {__file__}.php does not exist.
How to call function after “.”, javascript
I have this example function and I want to call it in this format: const myfunc = (string) => { return string.length } console.log(“check_length”.myfunc()) How can I do this? Thanks in advance for your replies! 1> Nina Scholz..: The only way is to mutate String using classic access functions Prototype this. String.prototype.myfunc = function () { return this.length; }; console.log(“check_length”.myfunc());
Replace last part of string, javascript
1> Tim Biegelei..: Just try \.\d+$ using regex Just replace the expression with an empty string: var input = “1.2.1”; input = input.replace(/\.\d+$/, “”); console.log(input);
Sharing of MD5 encryption algorithm implemented in Java, JavaScript, Oracle, and MySQL
MD5, the full name is Message Digest Algorithm 5 (message digest algorithm fifth edition). For details, please refer to Wikipedia: MD5 MD5 encryption is a byte array, but we generally use its hexadecimal string representation. Of course, hexadecimal strings are case-sensitive, in mysql database, Java, and Javascript In the language, lowercase strings are generally used to express, but in the package officially provided by Oracle database, uppercase strings are returned, which is a pitfall. If you want to execute md5 multiple times, you may need to convert to lowercase. The relevant code is as follows: 1. Java version of MD5 MD5Util.java package com.cncounter.util.common; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; /** * Java message digest algorithm MD5 tool class, in fact, the implementation of other digest algorithms is similar */ public class MD5Util { /** * Perform md5 digest encryption on text. This algorithm has been compared with the md5 digest generated by mysql and Javascript for consistency. * @param plainText * @return The letters in the return value are lowercase */ public static String md5(String plainText) { if (null == plainText) { plainText = “”; } String MD5Str = “”; try { // JDK 6 supports the following 6 message digest algorithms,…
Javascript, extending ES6 class setter will inherit getter
In Javascript, use the following illustration code: class Base { constructor() { this._val = 1 } get val() { return this._val } } class Xtnd extends Base { set val(v) { this._val = v } } let x = new Xtnd(); x.val = 5; console.log(x.val); // prints ‘undefined’ Instances x do not get val()… inherit from the Base class. In fact, Javascript will be missing when the setter is present The getter is treated as undefined. I have a situation where I have many classes that all have the exact same set of getters but unique setters. Currently, I just copy the getters in each class, but I’m refactoring and want to eliminate redundant code. Is there a way to tell JS to keep the base class’s getter, or does anyone have an elegant solution to this problem? 1> Patrick Robe..: This limitation is due to how Javascript handles property accessors behind the scenes. In ECMAScript 5, you The resulting prototype chain has the property descriptor for your class’s get method that defines val, and set is undefined method. In your Xtnd class you have another property descriptor for val hiding the entire property descriptor val of the base class…
Javascript, the solution you need for async problems
Currently creating an app using Angular, socket.io and express. However, I’m running into an async issue that I’m having trouble finding a solution for. Here’s the code: export class WebsocketService { this.socket; public connect() { const token = sessionStorage.getItem(‘token’); this.socket = io(‘http://localhost:3000’, { query: { token: token } }); } public getSocket () { // this function should only return this.socket when it is available return this.socket; } The idea is that first the websocket is connected once somewhere in the application, so the io function is called once: this.socket = io(‘http://localhost:3000′, { query: { token: token } }); Then in the rest of the application, this.socket should pass the properties. However, this.socket should always return the object and should wait for it if it does not exist . The implementation should also handle other parts of the application that try to call getSocket and return undefined. Basically, getSocket should never return undefined it should wait for a connection and then return this. socket. I tried some commits but I can’t seem to find an elegant solution. 1> Hyyan Abo Fa..: I don’t know why you need this connect method, but it’s a method export class WebsocketService { getSocket() {…