程式下載:尚虎雲產銷平台-銷售端
參考文章:尚虎雲產銷平台-銷售端軟體安裝手冊、用Python/Django/pythonanywhere實作農漁業產品交易行情
上架平台:pythonanywhere
1. Sales-side/apps/templates/home/Front page.html程式修改:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 | {% extends "layouts/base.html" %} {% comment %} 這個是網頁的title {% endcomment %} {% block title %} {% if web_inf.title %} {{ web_inf.title }} {% else %} 尚虎雲 {% endif %} {% endblock title %} {% comment %} 在這裡加入css {% endcomment %} {% block stylesheets %} <link href="{{ ASSETS_ROOT }}/css/Front page.css" rel="stylesheet" media="all" autostart="true"> <style> .active { /* 示例樣式 */ color: red; } .slide { display: inline-block; width: 100%; } .carousel-container { width: 100%; overflow: hidden; } .carousel-inner { display: flex; transition: margin-left 0.5s ease; } table, th, td { border: 1px solid white; border-collapse: collapse; } </style> {% endblock stylesheets %} {% block container %} <!--首頁--> <div class="bg1"> <div class="nav"> <a href="#" class="logo"> <img src="{% if web_inf.logo %}{{ web_inf.logo.url }}{% else %}{{ ASSETS_ROOT }}/images/favicon.png{% endif %}"> </a> <div class="nav-text"> <a href="#home">主頁</a> <a href="#trading">交易行情</a> <a href="#about">關於我們</a> <a href="#menu">賣家</a> <a href="#contact">聯絡我們</a> </div> </div> </div> <!--首頁--> <!--圖片輪播--> <section class="home" id="home"> <div class="slider"> <!-- list Items --> <div class="list"> {% for carousel in carousels %} {% if forloop.first %} <div class="item active"> {% else %} <div class="item"> {% endif %} <img src="{{ carousel.image.url }}"> <div class="content" style="color: {{ carousel.color }}"> {% if carousel.header %} <p> {{ carousel.header }} </p> {% endif %} {% if carousel.title %} <h2> {{ carousel.title }} </h2> {% endif %} {% if carousel.content %} <p> {{ carousel.content }} </p> {% endif %} </div> </div> {% endfor %} </div> <!-- button arrows --> <div class="arrows"> <button id="prev"><</button> <button id="next">></button> </div> <!-- thumbnail --> <div class="thumbnail"> {% for carousel in carousels %} {% if forloop.first %} <div class="item active"> {% else %} <div class="item"> {% endif %} <img src="{{ carousel.image.url }}"> {% if carousel.title %} <div class="title" style="color: {{ carousel.color }}"> {{ carousel.title }} </div> {% endif %} </div> {% endfor %} </div> </div> </section> <!--圖片輪播--> <!--最新行情--> <section class="trading" id="trading"> <div class="row" style="border:1px #ccc solid;padding:5px;margin-top:15px;color:white";> <center> {% for row in rows %} {% if forloop.first %} <table> <caption><h2>落花生市場交易情形</h2></caption> <tr> <th>交易日期</th> <th>作物代號</th> <th>作物名稱</th> <th>市場代碼</th> <th>市場名稱</th> <th>上價</th> <th>中價</th> <th>下價</th> <th>平均價</th> <th>交易量</th> </tr> {% endif %} <tr> <td><center>{{ row.交易日期 }}</center></td> <td><center>{{ row.作物代號 }}</center></td> <td><center>{{ row.作物名稱 }}</center></td> <td><center>{{ row.市場代號 }}</center></td> <td><center>{{ row.市場名稱 }}</center></td> <td><center>{{ row.上價 }}</center></td> <td><center>{{ row.中價 }}</center></td> <td><center>{{ row.下價 }}</center></td> <td><center>{{ row.平均價 }}</center></td> <td><center>{{ row.交易量 }}</center></td> </tr> {% if forloop.last %} </table> {% endif %} {% endfor %} </center> </row> </section> <!--最新行情--> <!--介紹--> {% if about %} <section class="about" id="about"> <h1 class="heading"> <span>about</span> us </h1> <div class="row"> <div class="image"> <img src="{{ about.image.url }}" alt=""> </div> <div class="content2"> <h3>{{ about.title }}</h3> {% if about.simple_introduce %} <p>{{ about.simple_introduce }}</p> {% endif %} {% if about.introduce %} <p>{{ about.introduce }}</p> {% endif %} {% if about.link %} <a href="{{ about.link }}" class="btn"> 關於更多 <span></span><span></span><span></span> </a> {% endif %} </div> </div> </section> {% endif %} <!--介紹--> <!--產品--> <section class="menu" id="menu"> <h1 class="heading">our <span>partner vendors</span> </h1> <div class="bix-container"> {% for parent in parents %} <div class="box"> <img src="{{ parent.seller_image.url }}" alt=""> <h3>{{ parent.seller_name }}</h3> <a href="{% url 'seller_detail' parent.id %}" class="btn"> 關於更多 <span></span><span></span><span></span> </a> </div> {% endfor %} </div> </section> <!--產品--> <!--聯絡--> <section class="contact" id="contact"> <h1 class="heading"><span>contact </span>us</h1> <div class="row"> {% if mapIframe %} {{ mapIframe.map_iframe | safe }} {% endif %} <form method="post"> {% csrf_token %} <h3>聯 絡 我 們</h3> <div class="inputBox"> <span class="fa-solid fa-user"></span> {{ form.name }} </div> <div class="inputBox"> <span class="fa-solid fa-envelope"></span> {{ form.email }} </div> <div class="inputBox"> <span class="fa-solid fa-phone"></span> {{ form.phone }} </div> <div class="inputBox"> <span class="fa-solid fa-question"></span> {{ form.question }} </div> <button type="submit" class="btn"> 提 交 <span></span><span></span><span></span> </button> </form> </div> </section> <!--聯絡--> <!--底部--> <section class="footer"> <div class="share"> {% if profiles.facebook_link %} <a href="{{ profiles.facebook_link }}" class="fa-brands fa-facebook"></a> {% endif %} {% if profiles.instagram_link %} <a href="{{ profiles.instagram_link }}" class="fa-brands fa-instagram"></a> {% endif %} {% if profiles.youtube_link %} <a href="{{ profiles.youtube_link }}" class="fa-brands fa-youtube"></a> {% endif %} </div> <div class="credit">© <script>document.write(new Date().getFullYear());</script> Copyrights 尚虎雲產銷平台</br><script>document.write(new Date().getFullYear());</script> All rights reserved | This template is made with Wen Qi</div> {% if profiles.phone_number %} <div class="credit">連絡電話: {{ profiles.phone_number }}</div> {% endif %} {% if profiles.contact_address %} <div class="credit">連絡地址: {{ profiles.contact_address }}</div> {% endif %} {% if profiles.real_name %} <div class="credit">聯絡人: {{ profiles.real_name }}</div> {% endif %} {% if profiles.description %} <div class="credit">個人簡介: {{ profiles.description }}</div> {% endif %} </section> <!--底部--> {% endblock container %} {% block javascripts %} <script> document.addEventListener("DOMContentLoaded", function() { {% if send_success %} alert("表單已提交"); {% endif %} }); function scroll() { var top = $(".bg1").offset().top; // 獲取導航欄變色的位置距頂部的高度 var scrollTop = $(window).scrollTop(); // 獲取當前窗口距頂部的高度 if (scrollTop <= top) { $('.nav').css('background-color', 'transparent'); } else { $('.nav').css('background-color', '#111111'); } } $(window).on('scroll', function() { scroll(); }); </script> <script src="{{ ASSETS_ROOT }}/js/Front page.js"></script> {% endblock javascripts %} |
2. Sales-side/apps/home/views.py程式修改
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | import traceback from django import template from django.http import HttpResponse, HttpResponseRedirect, JsonResponse from django.template import loader from django.urls import reverse from django.core.mail import send_mail from django.conf import settings from django.shortcuts import get_object_or_404 from .models import( Profile, WebBasicInf, CarouselImage, AboutUs, SellerInfo, ProductInfo, ProductImage, MapIframe ) from .forms import ContactForm import requests import json def index(request): context = {} try: context['profiles'] = Profile.objects.get() except Profile.DoesNotExist: pass try: context['mapIframe'] = MapIframe.objects.get() except MapIframe.DoesNotExist: pass try: context['about'] = AboutUs.objects.get() except AboutUs.DoesNotExist: pass try: context['web_inf'] = WebBasicInf.objects.get() except WebBasicInf.DoesNotExist: pass if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): name = form.cleaned_data['name'] email = form.cleaned_data['email'] phone = form.cleaned_data['phone'] question = form.cleaned_data['question'] subject = '聯絡表單提交' message = f'姓名: {name}\n電子郵件: {email}\n電話號碼: {phone}\n提問內容: {question}' email_from = settings.EMAIL_HOST_USER recipient_list = [email, context['profiles'].email] send_mail(subject, message, email_from, recipient_list) context["send_success"] = True else: form = ContactForm() context["form"] = form context["carousels"] = CarouselImage.objects.all() context["parents"] = SellerInfo.objects.all() r = requests.get('https://data.moa.gov.tw/Service/OpenData/FromM/FarmTransData.aspx') text = json.loads(r.text) rows = [] for row in text: if row['作物名稱'] is None: continue if '落花生' in row['作物名稱']: rows.append(row) context["rows"] = rows html_template = loader.get_template('home/Front page.html') return HttpResponse(html_template.render(context, request)) def seller_detail_view(request, id): context = {} context["seller"] = get_object_or_404(SellerInfo, id=id) html_template = loader.get_template('home/index.html') return HttpResponse(html_template.render(context, request)) def pages(request): context = {} try: context['web_inf'] = WebBasicInf.objects.get() except WebBasicInf.DoesNotExist: pass try: load_template = request.path.split('/')[-1] # 後台 if load_template == 'admin': return HttpResponseRedirect(reverse('admin:index')) # 紀錄目前是哪個模板 html_template = loader.get_template('home/' + load_template) return HttpResponse(html_template.render(context, request)) except template.TemplateDoesNotExist: traceback.print_exc() html_template = loader.get_template('home/page-404.html') return HttpResponse(html_template.render(context, request)) except: traceback.print_exc() html_template = loader.get_template('home/page-500.html') return HttpResponse(html_template.render(context, request)) def product_list(request, seller_id): products = ProductInfo.objects.filter(seller__id=seller_id).values() return JsonResponse(list(products), safe=False) def product_photos(request, product_id): images = ProductImage.objects.filter(product_id=product_id).values() return JsonResponse(list(images), safe=False) |
沒有留言:
張貼留言