国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Python代碼片段之Django靜態(tài)文件URL的配置

這篇具有很好參考價值的文章主要介紹了Python代碼片段之Django靜態(tài)文件URL的配置。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

首先要說明這段python代碼并不完整,而且我也沒有做過測試,只是我在工作時參考了其中的一些個方法。這是我在找python相關(guān)源碼資料里看到的一段代碼,是Django靜態(tài)文件URL配置代碼片段2,代碼中有些方法還是挺技巧的,做其它操作時可以參考著使用。需要完整代碼的伙伴們可以自已去找找看,如果有時間等,就等我把其它片段收集整理后再貼上來分享。

#!usr/bin/env python
#coding: utf-8
 
import logging
import os.path
 
DEBUG = True
TEMPLATE_DEBUG = DEBUG
HERE = os.path.dirname(os.path.abspath(__file__))
 
ADMINS = (
    # ('Your Name', 'your_email@example.com'),
)
 
MANAGERS = ADMINS
 
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'djangodemo',                      # Or path to database file if using sqlite3.
        'USER': 'root',                      # Not used with sqlite3.
        'PASSWORD': '',                  # Not used with sqlite3.
        'HOST': 'localhost',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '3306',                      # Set to empty string for default. Not used with sqlite3.
    }
}
 
# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# On Unix systems, a value of None will cause Django to use the same
# timezone as the operating system.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = 'Asia/Shanghai'
 
# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'zh-cn'
 
SITE_ID = 1
 
# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True
 
# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale
USE_L10N = True
 
MEDIA_ROOT = os.path.join(HERE, 'data').replace('\\','/')
 
STATIC_ROOT = os.path.join(HERE, 'static').replace('\\','/')
 
CAPTCHA_FONT=os.path.join(HERE,'static/Vera.ttf')
 
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
#MEDIA_ROOT = ''
 
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
MEDIA_URL = '/media/'
 
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
#STATIC_ROOT = ''
 
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'
 
# URL prefix for admin static files -- CSS, JavaScript and images.
# Make sure to use a trailing slash.
# Examples: "http://foo.com/static/admin/", "/static/admin/".
ADMIN_MEDIA_PREFIX = '/static/admin/'
 
# Additional locations of static files
STATICFILES_DIRS = (
    # Put strings here, like "/home/html/static" or "C:/www/django/static".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
)
 
# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
#   'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
 
# Make this unique, and don't share it with anybody.
#www.iplaypy.com
SECRET_KEY = '3d5&166r)l@xd4zc-a$iuw3nkyi99ee4!k3bjhy)ly1i8pc*b9'
#UPLOAD SETTINGS
FILE_UPLOAD_TEMP_DIR = os.path.join(HERE, 'data/upload/').replace('\\', '/')
FILE_UPLOAD_HANDLERS = ("django.core.files.uploadhandler.MemoryFileUploadHandler",
 "django.core.files.uploadhandler.TemporaryFileUploadHandler",)
DEFAULT_FILE_STORAGE = 'django.core.files.storage.FileSystemStorage'
# for user upload
ALLOW_FILE_TYPES = ('.jpg', '.jpeg', '.gif', '.bmp', '.png', '.tiff')
# unit byte
ALLOW_MAX_FILE_SIZE = 1024 * 1024
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
    'django.template.loaders.eggs.Loader',
)
 
MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
)
 
ROOT_URLCONF = 'urls'
 
TEMPLATE_DIRS = (
   os.path.join(HERE,'templates'),
)
 
TEMPLATE_CONTEXT_PROCESSORS = (  
    "django.core.context_processors.auth", 
    "d
2000
jango.core.context_processors.request",
    "django.core.context_processors.media", 
) 
INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # Uncomment the next line to enable the admin:
    'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    'django.contrib.admindocs',
    'blog',
    'account',
    'news',
    'photo',
    'rbac',
)
 
# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
# the site admins on every HTTP 500 error.
# See http://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.
LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'mail_admins': {
            'level': 'ERROR',
            'class': 'django.utils.log.AdminEmailHandler'
        }
    },
    'loggers': {
        'django.request': {
            'handlers': ['mail_admins'],
            'level': 'ERROR',
            'propagate': True,
        },
    }
}
#mail
EMAIL_HOST = 'smtp.gmail.com'                   #郵件smtp服務(wù)器
EMAIL_PORT = '25'                                        #端口
EMAIL_HOST_USER = 'code***@gmail.com'  #郵件賬戶
EMAIL_HOST_PASSWORD = '*********'      #密碼
EMAIL_USE_TLS = False

Python代碼片段之Django靜態(tài)文件URL的配置:文章來源地址http://www.zghlxwxcb.cn/news/detail-606912.html

#!usr/bin/env python
#coding: utf-8
from django.conf.urls.defaults import patterns, include, url
from django.conf import settings
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
 
urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'djangodemo.views.home', name='home'),
    # url(r'^djangodemo/', include('djangodemo.foo.urls')),
 
    # Uncomment the admin/doc line below to enable admin documentation:
    # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
 
    # Uncomment the next line to enable the admin:
    url(r'^$', 'account.views.index',name="index"),
    url(r'^admin/', include(admin.site.urls)),
    url(r'^blog/', include('blog.urls')),
    url(r'^account/', include('account.urls')),
    url(r'^news/', include('news.urls')),
    url(r'^photo/', include('photo.urls')),
    url(r'^rbac/', include('rbac.urls')),
    url(r'^static/(?P<path>.*)$','django.views.static.serve',{'document_root':settings.STATIC_ROOT}),
    url(r'^media/(?P<path>.*)$','django.views.static.serve',{'document_root': settings.FILE_UPLOAD_TEMP_DIR}),
)

到了這里,關(guān)于Python代碼片段之Django靜態(tài)文件URL的配置的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進(jìn)行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • 局域網(wǎng)管理軟件Python示例代碼片段

    局域網(wǎng)管理軟件是企業(yè)和組織中管理和監(jiān)控網(wǎng)絡(luò)設(shè)備的關(guān)鍵工具。這些軟件可以幫助管理員輕松地管理局域網(wǎng)中的設(shè)備,確保網(wǎng)絡(luò)的穩(wěn)定性和安全性。在本文中,我們將探討局域網(wǎng)管理軟件的重要性,并提供一個簡單的示例代碼來演示如何使用Python編寫一個基本的局域網(wǎng)設(shè)備

    2024年02月08日
    瀏覽(16)
  • Django基礎(chǔ)入門?:更新書籍信息 刪除書籍條目信息 Django靜態(tài)文件配置

    Django基礎(chǔ)入門?:更新書籍信息 刪除書籍條目信息 Django靜態(tài)文件配置

    ??????個人簡介:以山河作禮。 ??????: Python領(lǐng)域新星創(chuàng)作者,CSDN實力新星認(rèn)證,阿里云社區(qū)專家博主,CSDN內(nèi)容合伙人 ????:Web全棧開發(fā)專欄:《Web全棧開發(fā)》免費專欄,歡迎閱讀! ????: 文章末尾掃描二維碼可以加入粉絲交流群,不定期免費送書。 更改原有的書

    2024年02月16日
    瀏覽(157)
  • Python web實戰(zhàn)之Django URL路由詳解

    ? 技術(shù)棧:Python、Django、Web開發(fā)、URL路由 Django是一種流行的Web應(yīng)用程序框架,它采用了與其他主流框架類似的URL路由機制。URL路由是指將傳入的URL請求映射到相應(yīng)的視圖函數(shù)或處理程序的過程。 URL路由是Web開發(fā)中非常重要的概念,它將URL映射到特定的視圖函數(shù)。在Django中,

    2024年02月14日
    瀏覽(698)
  • Python Django 零基礎(chǔ)從零到一部署服務(wù),Hello Django!全文件夾目錄和核心代碼!

    在這篇文章中,我將手把手地教你如何從零開始部署一個使用Django框架的Python服務(wù)。無論你是一個剛開始接觸開發(fā)的新手,還是一個有經(jīng)驗的開發(fā)者想要快速了解Django,這篇教程都會為你提供一條清晰的路徑。我們將從環(huán)境搭建開始,一步一步地創(chuàng)建一個可以處理GET和POST請求

    2024年02月12日
    瀏覽(169)
  • Python學(xué)習(xí)之路:Django項目遇到ImportError: cannot import name ‘url‘ from ‘django.conf.urls‘解決方法(親測有效)

    配置:Pthon 3.8.10-Django 4.1.1 使用命令創(chuàng)建數(shù)據(jù)庫時: python manage.py migrate 提示錯誤: ?from django.conf.urls import re_path as url ImportError: cannot import name \\\'re_path\\\' from \\\'django.conf.urls\\\' 經(jīng)查閱相關(guān)資料,并實際操作,解決問題,具體辦法往下: 修改生成項目下的urls.py文件中的:from django.c

    2023年04月21日
    瀏覽(27)
  • VSCode代碼片段配置

    VSCode代碼片段配置

    1.在VSCode設(shè)置 配置用戶代碼片段菜單添加 ?2.在輸入框中選擇新建代碼片段 ? 3.輸入代碼片段名稱.例如:copyright 4. 生成第3步名稱的代碼片段文件,默認(rèn)位置:C:Users 你的電腦名稱 AppDataRoamingCodeUsersnippets 5. 代碼片段模板的解釋如下: 重點關(guān)注scope+prefix+body參數(shù)的配置, ? ? ?

    2024年02月04日
    瀏覽(34)
  • python 獲取阿里云oss文件分享url

    阿里云文檔鏈接:前言 在阿里云把所有東西都配好之后按照代碼填寫對應(yīng)的?AccessKeyId、yourAccessKeySecret等 ?

    2024年02月12日
    瀏覽(89)
  • Python學(xué)習(xí)筆記:Requests庫安裝、通過url下載文件

    Python學(xué)習(xí)筆記:Requests庫安裝、通過url下載文件

    在pipy或者github下載,通常是個zip,解壓縮后在路徑輸入cmd,并運行以下代碼 ?安裝完成后,輸入python再輸入import requests得到可以判斷時候完成安裝 ?2.通過url下載文件 使用的是urllib模塊

    2024年02月10日
    瀏覽(86)
  • python html(文件/url/html字符串)轉(zhuǎn)pdf

    python html(文件/url/html字符串)轉(zhuǎn)pdf

    安裝庫 第二步 下載程序 wkhtmltopdf https://wkhtmltopdf.org/downloads.html 下載7z壓縮包 解壓即可, 無需安裝 解壓后結(jié)構(gòu)應(yīng)該是這樣, 我喜歡放在項目里, 相對路徑引用(也可以使用絕對路徑, 放其他地方) 最好每個都像 string_to_pdf 函數(shù)一樣, 捕獲一下錯誤, 可以使程序更健壯, 避免轉(zhuǎn)換失敗

    2024年02月08日
    瀏覽(34)
  • Python 進(jìn)階 — Pylint 靜態(tài)代碼檢查工具

    與 Flake8 一般,Pylint 也是一款 Python 的靜態(tài)代碼檢查工具,它會分析 Python 代碼中的錯誤,查找不符合代碼風(fēng)格標(biāo)準(zhǔn)和有潛在問題的代碼。除了平常代碼分析工具的作用之外,Pylint 還提供了更多的功能,如:檢查一行代碼的長度,變量名是否符合命名標(biāo)準(zhǔn),一個聲明過的接口

    2023年04月08日
    瀏覽(35)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包