static

PHP: self:: vs parent:: with extends

我只是一个虾纸丫 提交于 2020-01-22 05:19:17
问题 I'm wondering what is the difference between using self:: and parent:: when a static child class is extending static parent class e.g. class Parent { public static function foo() { echo 'foo'; } } class Child extends Parent { public static function func() { self::foo(); } public static function func2() { parent::foo(); } } Is there any difference between func() and func2() and if so then what is it ? Thank you Regards 回答1: Child has foo() Parent has foo() self::foo() YES YES Child foo() is

What's the best practice to keep all the constants in Flutter?

非 Y 不嫁゛ 提交于 2020-01-22 04:53:33
问题 What's the best programming practice to create a constant class in Flutter to keep all the application constants for easy reference. I know that there is const keyword in Dart for creating constant fields, but is it okay to use static along with const, or will it create memory issues during run-time. class Constants { static const String SUCCESS_MESSAGE=" You will be contacted by us very soon."; } 回答1: While there are no technical issues with static const , architecturally you may want to do

What's the best practice to keep all the constants in Flutter?

穿精又带淫゛_ 提交于 2020-01-22 04:53:05
问题 What's the best programming practice to create a constant class in Flutter to keep all the application constants for easy reference. I know that there is const keyword in Dart for creating constant fields, but is it okay to use static along with const, or will it create memory issues during run-time. class Constants { static const String SUCCESS_MESSAGE=" You will be contacted by us very soon."; } 回答1: While there are no technical issues with static const , architecturally you may want to do

django使用静态文件

烂漫一生 提交于 2020-01-22 04:08:41
  首先说这里我讲的是测试时候的,并不是部署时候的内容(因为我还没有测试)。 1.在setting.py文件里面,修改: 在STATICFILES_DIRS 里面添加你的静态文件目录,这里相对目录即可,比如我放的是:'static/'2.在你的项目里面,递归创建你的静态文件:比如我的:prjectroot/static/css/base.css3.在projectroot目录下运行:python manage.py collectstatic 4.使用的时候,在你的模板文件里面添加一句即可: <head>   <link href="/static/css/base.css" rel="stylesheet" type="text/css"> </head>   注意:不在在setting.py里面编辑STATIC_ROOT内容,引文它已经提示给你了: Don't put anything in this directory yourself; store your static files in apps' "static/" subdirectories and in STATICFILES_DIRS 来源: https://www.cnblogs.com/slider/archive/2012/06/26/2563153.html

django 模板使用静态文件

蓝咒 提交于 2020-01-22 03:48:59
1、新建项目 2、新建app,并在install_app中添加该app 3、和app文件夹并列新建static、和TEMPLATES 文件夹,分别放静态文件和模板 4、setting.py中设置 TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [ os.path.join(BASE_DIR, "templates").replace("\\", "/") ], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ], }, }, ] BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) STATIC_URL = '/static/'

Django设置

[亡魂溺海] 提交于 2020-01-22 03:48:02
运行 django-admin.py startproject [project-name] 命令会生成一系列文件,在Django 1.6版本以后的 settings.py 文件中有以下语句: # Build paths inside the project like this: os.path.join(BASE_DIR, ...) import os BASE_DIR = os.path.dirname(os.path.dirname(__file__)) 这里用到了python中一个神奇的变量 __file__ 这个变量可以获取到当前文件(包含这个代码的文件)的路径。os.path.dirname(__file__) 得到文件所在目录,再来一个os.path.dirname()就是目录的上一级,BASE_DIR 即为 项目 所在目录。我们在后面的与目录有关的变量都用它,这样使得移植性更强。 # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True TEMPLATE_DEBUG = True DEBUG=True 时,如果出现 bug 便于我们看见问题所在,但是部署时最好不要让用户看见bug的详情,可能一些不怀好心的人攻击网站,造成不必要的麻烦。 ALLOWED_HOSTS =

Django-03-静态文件配置

让人想犯罪 __ 提交于 2020-01-22 03:41:42
一、 django静态文件配置原理 静态文件配置就是为了让用户请求时django服务器能找到静态文件返回。 首先要理解几个概念: 媒体文件:用户上传的文件 静态文件:css,js,image等 开发环境:使用django内置服务器处理静态文件 生产环境:使用apache2/nginx服务器处理静态文件映射 静态文件交由Web服务器处理,Django本身不处理静态文件。简单的处理逻辑如下(以nginx为例): URI请求-----> 按照Web服务器里面的配置规则先处理,以nginx为例,主要求配置在nginx. #conf里的location   |---------->如果是静态文件,则由nginx直接处理   |---------->如果不是则交由Django处理,Django根据urls.py里面的规则进行匹配 以上是部署到Web服务器后的处理方式,为了便于开发,Django提供了在开发环境的对静态文件的处理机制,方法是这样: 1、在INSTALLED_APPS里面加入'django.contrib.staticfiles', 2、在urls.py里面加入 if settings.DEBUG: urlpatterns += patterns('', url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {

0、django配置

北慕城南 提交于 2020-01-22 03:40:43
运行 django-admin.py startproject [project-name] 命令会生成一系列文件,在Django 1.6版本以后的 settings.py 文件中有以下语句: 1 2 3 # Build paths inside the project like this: os.path.join(BASE_DIR, ...) import os BASE_DIR = os.path.dirname(os.path.dirname(__file__)) 这里用到了python中一个神奇的变量 __file__ 这个变量可以获取到当前文件(包含这个代码的文件)的路径。os.path.dirname(__file__) 得到文件所在目录,再来一个os.path.dirname()就是目录的上一级,BASE_DIR 即为 项目 所在目录。我们在后面的与目录有关的变量都用它,这样使得移植性更强。 1 2 3 # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True TEMPLATE_DEBUG = True DEBUG=True 时,如果出现 bug 便于我们看见问题所在,但是部署时最好不要让用户看见bug的详情,可能一些不怀好心的人攻击网站,造成不必要的麻烦。 1

django--static文件的管理

北战南征 提交于 2020-01-22 02:59:34
做网站,不会前端总是不行的,就算自己不深入学习成为前端大拿,套用别人的css和js总还是要会的,因此,静态文件的引用成为了一个topic。 Django创建一个新项目的时候已经默认产生了一些配置,应对小项目足够了,如果追求完美的话,总还需要多了解一些。列出了以下topic。 1、 一个不做任何额外配置的django项目能怎么处理static? 2、 好好规划的static文件目录又是什么样子的? 3、 部署到生产该怎么办? 4、 Django中谁在管理着这些static文件?纯代码层面了哟 答: 1、 没有额外自己添加配置时,和static文件有关的settings,如下(从settings.py中摘出来的) # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # Application definition INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions',

django中的静态文件管理

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-22 02:58:23
  一个站点通常需要保存额外的文件,比如图片 css样式文件 js脚本文件 ,在django中,倾向于将这些文件称为 静态文件。django提供了django.contrib.staticfiles 模块来帮助我们方便的管理静态文件。 配置静态文件的两种方式:   1 配置单独app下的静态文件,比如某个app下的单独的图片。   2 配置整个project下的静态文件,适用于那些和单独app关联不大的文件,比如jquery bootstrap 等等 配置步骤: 1 首先,我们需要确认在settings.py文件中的INSTALLED_APPS变量中存在 django.contrib.staticfiles 1 INSTALLED_APPS = ( 2 'django.contrib.admin', 3 'django.contrib.auth', 4 'django.contrib.contenttypes', 5 'django.contrib.sessions', 6 'django.contrib.messages', 7 'django.contrib.staticfiles', 8 ) 2.1 如果我们要配置单独app下的静态文件的话,执行此步骤。   在settings.py文件中定义 STATIC_URL 变量。 1 STATIC_URL = '/static/'