• 修改url,


    第一种场景:

       无论url怎么变,表单里面的url始终不变

      http://127.0.0.1:8000/CC/indexssssssssssssssssss/

    url(r'^indexssssssssssssssssss/', views.index,name='indexx'),

    <form action="{% url 'indexx' %}" method="POST">#}

    def index(request):
    return render(request,"index1.html",{'user_dict':USER_DICT}



    第二种场景:

        url加ID

       http://127.0.0.1:8000/CC/indexssssssssssssssssss/3/

    url(r'^indexssssssssssssssssss/(d+)/', views.index,name='indexx'),

    <form action="{% url 'indexx' 3 %}" method="POST">

    def index(request,nid):
    print nid
    return render(request,"index1.html",{'user_dict':USER_DICT})


    第三种场景显示当前url:(适用于在当前页面提交之后继续留在当前页面)

       http://127.0.0.1:8000/CC/indexssssssssssssssssss/33/

    url(r'^indexssssssssssssssssss/(d+)/', views.index,name='indexx'),
     <form action="{{request.path_info}}" method="POST">#}
    def index(request,nid):
    print request.path_info
    return render(request,"index1.html",{'user_dict':USER_DICT,})


    对URL路由关系进行命名, ***** 以后可以根据此名称生成自己想要的URL *****

    url(r'^asdfasdfasdf/', views.index, name='i1'),
    url(r'^yug/(d+)/(d+)/', views.index, name='i2'),
    url(r'^buy/(?P<pid>d+)/(?P<nid>d+)/', views.index, name='i3'),


    #反转生成url
    def func(request, *args, **kwargs):
    from django.urls import reverse

    url1 = reverse('i1') # asdfasdfasdf/
    url2 = reverse('i2', args=(1,2,)) # yug/1/2/
    url3 = reverse('i3', kwargs={'pid': 1, "nid": 9}) # buy/1/9/


    xxx.html

    {% url "i1" %} # asdfasdfasdf/
    {% url "i2" 1 2 %} # yug/1/2/
    {% url "i3" pid=1 nid=9 %} # buy/1/9/

    注:
    # 当前的URL

  • 相关阅读:
    keepalive高可用集群(nginx)
    nginx负载均衡
    linux-------lnmp安装
    nginx编译安装
    Django+MySQL安装配置详解(Linux)[更新为1.8.2版]
    linux性能监控——CPU、Memory、IO、Network
    linux 时钟时间,用户CPU时间,系统CPU时间 .
    指针用作传出参数时,需要二级指针
    僵尸进程&孤儿进程
    XHProf是一个分层PHP性能分析工具。
  • 原文地址:https://www.cnblogs.com/qiangayz/p/8972588.html
Copyright © 2020-2023  润新知