vue
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>欢迎访问首页</title>
<script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
<!-- <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>-->
</head>
<body>
<h1>欢迎访问首页</h1>
<H2>我是副标题</H2>
<!-- {% for i in all_links %}-->
<!-- <a href="{{i.link_url}}">{{i.link_name}}</a>-->
<!-- {% endfor %}-->
<div id="links_div">
<div v-for="i in all_links">
<a :href="[[ i.link_url ]]">[[ i.link_name ]]</a>
</div>
</div>
<script>
console.log('你好啊')
var div = new Vue({
el:"#links_div",
delimiters:["[[","]]"],
data:{
all_links:{{ all_links|safe }}
}
})
</script>
</body>
</html>
url
"""
URL configuration for zcx_db_make project.
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/5.0/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from myapp.views import *
urlpatterns = [
path('admin/', admin.site.urls),
path('home/',home),
path('/',home),
]
view
from django.shortcuts import render
from myapp.models import *
# Create your views here.
def home(request):
all_links = DB_links.objects.all()
list_all_links = list(all_links.values())
return render(request,'home.html',{"all_links":list_all_links})
model
from django.db import models
# Create your models here.
class DB_links(models.Model):
link_name = models.CharField(max_length=50,null=True,blank=True)
link_url = models.CharField(max_length=300, null=True, blank=True)
def __str__(self):
return self.link_name
标签:vue,入门,links,views,django,home,import,path,name
From: https://blog.csdn.net/daxiashangxian/article/details/141749512