以下為利用iview-admin + django 做的一個最基本的增刪改查例子。
讓客戶滿意是我們工作的目標,不斷超越客戶的期望值來自于我們對這個行業(yè)的熱愛。我們立志把好的技術通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領域值得信任、有價值的長期合作伙伴,公司提供的服務項目有:域名注冊、虛擬空間、營銷軟件、網(wǎng)站建設、石臺網(wǎng)站維護、網(wǎng)站推廣。git clone https://github.com/iview/iview-admin.git
cd iview-admin
修改.eslintrc.json
17 "no-console": ["off"],
21"no-fallthrough": 0,
npm install
npm run dev
如果報錯修改
build/webpack.dev.config.js
11 const buf = Buffer.from('export default "development";');
build/webpack.prod.config.js
15 const buf = Buffer.from('export default "development";');
import axios from 'axios';
Vue.prototype.axios = axios;
npm install axios
export const otherRouter = {
path: '/',
name: 'otherRouter',
redirect: '/home',
component: Main,
children: [
{ path: 'asset-info/:id', title: '資產(chǎn)詳情', name: 'asset-info', component: () => import('@/views/asset/asset-info.vue') },
{ path: 'asset-edit/:id', title: '資產(chǎn)編輯', name: 'asset-edit', component: () => import('@/views/asset/asset-edit.vue') },
]
};
export const appRouter = [
{
path: '/asset',
icon: 'key',
name: 'asset',
title: '資產(chǎn)管理',
component: Main,
children: [
{ path: 'asset', title: '資產(chǎn)管理', name: 'asset-index', component: () => import('@/views/asset/asset.vue') },
{ path: 'asset-add', title: '資產(chǎn)添加', name: 'asset-add', component: () => import('@/views/asset/asset-add.vue') },
]
},
]
資產(chǎn)管理
提交錯誤
{{ e }}
資產(chǎn)詳情
{{ key }} {{ item }}
提交錯誤
{{ e }}
pip install djangorestframework django-cors-headers
settings.py
INSTALLED_APPS = [
'rest_framework',
'corsheaders',
]
# http://www.django-rest-framework.org/api-guide/permissions/#api-reference
# rest-framework 權限分類,現(xiàn)在是默認管理員可以訪問
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.BasicAuthentication',
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.TokenAuthentication',
),
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.AllowAny',
# 'rest_framework.permissions.IsAdminUser',
),
}
MIDDLEWARE = [
...
'corsheaders.middleware.CorsMiddleware', ##添加此項目
'django.middleware.common.CommonMiddleware',
...
]
##允許跨域的地址
CORS_ORIGIN_WHITELIST = (
"localhost:8080"
)
APPEND_SLASH=False
asset/models.py
class AssetLoginUser(models.Model):
hostname = models.CharField(max_length=64, verbose_name='名稱', unique=True)
username = models.CharField(max_length=64, verbose_name="用戶名", default='root', null=True, blank=True)
password = models.CharField(max_length=256, blank=True, null=True, verbose_name='密碼')
ps = models.CharField(max_length=10240, verbose_name="備注", null=True, blank=True)
ctime = models.DateTimeField(auto_now_add=True, null=True, verbose_name='創(chuàng)建時間', blank=True)
utime = models.DateTimeField(auto_now=True, null=True, verbose_name='更新時間', blank=True)
class Meta:
db_table = "AssetLoginUser"
verbose_name = "資產(chǎn)用戶"
verbose_name_plural = '資產(chǎn)用戶'
def __str__(self):
return self.hostname
urls.py
path('asset', api.AssetList.as_view(), name='asset_api_list'),
path('asset/', api.AssetDetail.as_view(), name='asset_api_detail'),
asset/serializers.py
from rest_framework import serializers
from .models import AssetLoginUser
class AssetSerializer(serializers.ModelSerializer):
class Meta:
model = AssetLoginUser
fields = '__all__'
asset/api.py
from rest_framework import generics
from .models import AssetLoginUser
from .serializers import AssetSerializer
from rest_framework import permissions
class AssetList(generics.ListCreateAPIView):
queryset = AssetLoginUser.objects.all()
serializer_class = AssetSerializer
permission_classes = (permissions.AllowAny,)
class AssetDetail(generics.RetrieveUpdateDestroyAPIView):
queryset = AssetLoginUser.objects.all()
serializer_class = AssetSerializer
permission_classes = (permissions.AllowAny,)
另外有需要云服務器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。