问题1,
当我将网站部署到云时。我必须设置Debug=False
。
但是仅索引视图可以加载statics
,其他视图则始终加载子目录static
。
我查看uwsgi日志。消息如下:
[pid: 6505|app: 0|req: 141/141] 117.10.182.55 () {42 vars in 836 bytes} [Fri Jul 6 01:50:58 2018] GET /search/static/js/bootstrap-datetimepicker.min.js => generated 122 bytes in 0 msecs (HTTP/1.1 404) 3 headers in 101 bytes (1 switches on core 0)
[pid: 6505|app: 0|req: 142/142] 117.10.182.55 () {42 vars in 792 bytes} [Fri Jul 6 01:50:58 2018] GET /search/static/js/search.js => generated 100 bytes in 0 msecs (HTTP/1.1 404) 3 headers in 101 bytes (1 switches on core 0)
我已经完成collectstatic
到我的project/static
文件夹中。
这是我的设置:
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR,'static'),
)
以下是nginx
中的静态设置。
location ^~ /static {
alias /var/www/erp/src/static/;
}
模板中的静态
<!DOCTYPE html>
{% load staticfiles %}
<link href="{% static "vendor/bootstrap/css/bootstrap.min.css" %}" rel="stylesheet">
erp.url:
from django.contrib import admin
from django.urls import include, path
from django.conf.urls import url
from src import views
urlpatterns = [
path('', include('src.urls')),
]
src.url:
from . import views
from django.conf.urls import url
from django.conf.urls.static import static
from django.contrib import admin
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
urlpatterns = [
path('login/', views.login,name='login'),
path('logout/',views.logout,name='logout'),
# path('', views.index.as_view(), name='index'),
path('purchase/', views.purchase, name='purchase'),
path('sales/', views.sales, name='sales'),
path('search/find/',views.find, name='find'),
path('search/buyer/',views.Buyer, name='buyer'),
# path('sales.html', views.sales, name='sales'),
path('', views.index, name='index'),
path('search/', views.search, name='search'),
path('products/',views.products,name='products'),
url(r'^(?P<Vchtype>[0-9]+)_(?P<Vchcode>[0-9]+)/$', views.IndexDetail, name='detail'),
url(r'^(?P<Vchcode>[0-9]+)/$', views.SalesDetail, name='sdetail'),
# path('indexnew.html', views.indexnew, name='index'),
]
问题2,
在一页中,当我想切换到另一页时,链接始终包含当前页。例如,当我打开搜索页面并单击href
链接以建立索引时。 href
将是/search/index/
href
链接写为:
href="{% url 'name' %}"
默认为模板设置:
ROOT_URLCONF = 'erp.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR,"templates")],
'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',
],
},
},
]
我想念什么吗?