Brief for Django using 3

DRY::(Don’t Repeat Yourself)
Django provides with a lot of high-efficient tools which can speed up your developing process. Learning to use them is a big deal, however, you are going to learn much more than the syntax itself.
In a form, use {% csrf_token %} is an easy and fast way to be shut cross-domin requests down.
like

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>form</title>
</head>
<body>
<p>{% if error_message %}{{ error_message }}</p>{% endif %}
<h1>form</h1>
<form action="{% url 'testx:form_action_test'%}" method="post">
    {% csrf_token %}
    {{ student.student_id }}
    stuid
    <input type="text" name="stuid"><BR>
    stuname
    <input type="text" name="stuname">
    <input type="submit" value="GO">
</form>


</body>
</html>

To use the “student” mentioned in the code, you need to create a model for you database.
for example, if you modify your models.py into this

from django.db import models

# Create your models here.
class Student(models.Model):
    student_id = models.CharField(max_length=30, default='0')
    student_name = models.CharField(max_length=20, default='no_name')

when processing a object of Student in views.py, you can just create an object of Student and then change the values of its member and then use Student’s base method save to add your new object to DB.

    stu = Student()
    params = request.POST
    stuid = params['stuid']
    stuname = params['stuname']
    stu.student_id = stuid
    stu.student_name = stuname
    stu.save()

After you’ve got the data from the form and added it to your database, you may want to show a result page to your visitor and the method you just used is a fully back-end method you may want your visitor to redirect to that result page.
use django.http.HttpResponseRedirect and django.urls.reverse to do the job.
like return HttpResponseRedirect(reverse('form:result', args=(pk,))) this args is the url argument normally transferred by browsers.

when it comes to the front-end method, it’s even faster to be built by Django’s generic class.

from django.views import generic
class ResultView(generic.DetailView):
  model = Student
  template_name = 'form/formResult.html'
class IndexView(generic.ListView):
 template_name = '/form/index.html'
 context_object_name = 'all_students'
 def get_queryset(self):
  return Student.objects.all()

Use DetailView when you want to see some detail, because this basic class requires the name of you model and of course the template’s name.

It can automatically get the object from url argument where you must only use some parameters like <int:pk> and such, which will be named as “student”, the lower case of Student.

In a ListView class you don’t have to specify your model’s name, rather you should specify the list’s name in HTML and how you get the list, the method.

Their url.py should look like this.

from django.urls import path
from . import views
from . import apps
app_name = apps.TestxConfig.name # my app name is 'testx'
urlpatterns = [
    path('', views.IndexView.as_view(), name='index'),
    path('result/<int:pk>', views.ResultView.as_view(), name='form_result'),
]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
3D Animation for the Raw Beginner Using Autodesk Maya, 2nd Edition by Roger King Chapman and Hall/CRC English 2019-02-16 452 pages 5.0/5.0 2 reviews Details Title: 3D Animation for the Raw Beginner Using Autodesk Maya, 2nd Edition Author: Roger King Length: 452 pages Edition: 2 Language: English Publisher: Chapman and Hall/CRC Publication Date: 2019-02-16 ISBN-10: 0815388780 ISBN-13: 9780815388784 Sales Rank: #1038614 (See Top 100 Books) Categories Computers & Technology Graphics & Design Programming Textbooks Computer Science Description 3D Animation for the Raw Beginner Using Autodesk Maya is a hands-on academic textbook as well as a do-it-yourself training manual for the individual animator. This second edition has been completely rewritten to take into account updates to Autodesk Maya, including Autodesk’s renderer, Arnold. It contains entirely new examples and tutorial lessons. All 612 images are in full color. The book directs the reader to the parts of Maya that must be mastered in order to create complete 3D projects, and thus it simplifies the process of taking on Maya’s vast and intricate interface, while giving the reader a firm foundation on which to build future knowledge of Maya. It also presents brief examples of other popular 3D applications and rendering engines. This principles-based, yet pragmatic book: Introduces the basic steps of the 3D modeling, materials, animation, lighting, and rendering processes. Presents clear and concise tutorials that link key concepts to practical techniques. Includes access to a webpage for the book: https://buzzking.com/AnimationTextbook/AnimationTextbook.html. On this webpage are videos that cover many of the lessons in the book, as well as video tutorials that present bonus material not included in the book. Frees instructors from the painstaking task of developing step-by-step examples to present Maya’s complex interface and basic capabilities. Boasts an easy-to-follow, tutorial-based learning style ideal for

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值