Javascript 使用django python将按钮链接到所需的html

Javascript 使用django python将按钮链接到所需的html,javascript,python,html,django,Javascript,Python,Html,Django,我试图建立一个网页,如果我有两个按钮,我可以参考不同的链接到他们。我曾多次尝试提取表单、javascript、ahref中单击按钮的信息,但有些东西工作不正常。 目前我正在尝试以下代码: 征求意见 def indiCountData(request): if request.POST.get('US'): (code inside working) return render(request,'india.html',context)

我试图建立一个网页,如果我有两个按钮,我可以参考不同的链接到他们。我曾多次尝试提取表单、javascript、ahref中单击按钮的信息,但有些东西工作不正常。 目前我正在尝试以下代码: 征求意见

def indiCountData(request):
if request.POST.get('US'):
            (code inside working)
            return render(request,'india.html',context)
        elif request.POST.get('India'):
            (code inside working)
            return render(request,'india.html',context)
用于html

<button onClick="myOnClickFn()">US</button>
           <script>
              function myOnClickFn(){
                  document.location.href="us.html";
              }
           </script>
           <button onClick="mynClickFn()">India</button>
           <script>
              function mynClickFn(){
                  document.location.href="india.html";
              }
           </script>
view covi.views.indiCountData未返回HttpResponse对象。它没有返回任何结果

如果你用这个

path('',views.home,name='home'),
    path('us.html',views.indiCountData,name=''),
    path('india.html',views.indiCountData,name=''),
 path('',views.home,name='home'),
        path('',views.indiCountData,name='us'),
        path('',views.indiCountData,name='india'),
404错误代码


请引导我,我在这里感到困惑,非常感谢您的回答。

由于JavaScript代码更改了
文档。位置
,两个按钮都在发出GET请求。但是django view函数检查
request.POST
是否包含“US”或“India”,如果
分支,则不访问任何
,并隐式返回None

如果
POST
不是您想要的,那么将不同路径的视图分开可以简化:

path(“”,views.home,name='home'),
路径('us.html',views.usPage,name=''),
路径('india.html',views.indiaPage,name=''),
def usPage(请求):
(内部工作代码)
返回呈现(请求,'us.html',上下文)
def indiaPage(请求):
(内部工作代码)
返回呈现(请求,'india.html',上下文)

非常感谢!!!成功了。我在这上面苦读了很长时间。