English 中文(简体)
DJANGO and AJAX: how to prevent a page from refreshing when i click on the Itton (without jQuery)
原标题:DJANGO and AJAX: how to prevent a page from refreshing when i click on the button (without jQuery)

在<代码>home.hmtl 页: 1 (独立后,不与数据库连接,而是与清单连接)和<代码>textarea。 我没有使用该数据库。 当我点击纽顿时,我想在文本中印刷一些案文(案文载于<条码>views.py文档中)。

www.un.org/Depts/DGACM/index_spanish.htm 我想要获得什么? 一切都正确发生,但网页在点击后立即重载。 我只用Django试图解决这一问题,但我没有(可能不可能)读到什么解决办法是使用<条码>Ajax<代码>、<条码>jQuery和<条码>中的内容。 我愿与AJax(,)一道解决这一问题。 j Query, and Potential Without Javascript. I m New to Django

<>>Considerations: 我在Stackoverflow或各种辅导方面发现了许多问题,但我无法回答。 很显然,即使问题相似,但每一种解决办法都是不同的,问题与解决办法不同。 通常发现的一种解决办法一,但并非对我而言,是用<条码> 类型=submit/code>取代“条码” ,然后添加“条码><<>>>,对 Java文的功能具有约束力。 我不需要在贾瓦特履行这一职能,因为我要把所有东西都保存在案卷中(该项目将拥有数百个 com子,我想在大档案中而不是在 Java文中加以管理)。

当我点击纽子时,我怎么能阻止该页重载? (与数据库无关,但与清单有关)。 I m New to Django. 我能否用解决办法向我展示这部法典? 我在晚上都在寻找解决办法。 你的帮助将受到高度赞赏。 谢谢大家。

<>

home.html (index >login > home)

索引:127.0.0.1:8000/。 Home.html will only open after fulllogin. 在我看来,表格的地址是127.0.0.1:8000/home,在我点击分机一时,我仍获得127.0.0.1:8000/home(直截了当)。 很显然,我以缩短和缩短的方式写了html:

{% extends  app1/base.html  %}

{% load static %}

{% block content %}

<div class="container p-5">
  <div class="row mx-auto">
    <div class="col-6">
      <form action="" method="POST" novalidate class="form-group">
        {% csrf_token %}
        <select name="color" class="form-select" >
          {% for i in color_choices %}
          <option value="{{i}}">{{i}}</option>
          {% endfor %}
        </select>
        <textarea class="form-control" name="msg" cols="30" rows="10">{{message}}</textarea>
        <button class="btn btn-primary mt-3" type="submit">Submit</button>
      </form>
    </div>
  </div>
</div>
{% endblock content%}

<>views.py

@login_required
def home(request):
  color_choices = ("Red","Blue","Black","Orange")
  message =  
  if request.method =="POST":
    picked = request.POST.get( color )
    if picked ==  Red :
      message = "<<< You chose red"
      print(message)
    elif picked ==  Blue :
        message = "<<< You chose blue"
    elif picked ==  Black :
        message = "<<< You chose black"
    else:
        message = "<<< Oh no, you chose orange"
  context = { message :message, color_choices :color_choices}
  return render(request,  app1/home.html , context)

<>forms.py

from django import forms

class SimpleCombobox(forms.Form):
    Col1 =  Red 
    Col2 =  Blue 
    Col3 =  Black 
    Col4 =  Orange 
      
    COLOR_CHOICES = (
        (Col1, u"Red"),
        (Col2, u"Blue"),
        (Col3, u"Black"),
        (Col4, u"Orange"),
    )
    cities = forms.ChoiceField(choices=COLOR_CHOICES)


class SimpleTextbox(forms.Form):
    coverletter = forms.CharField(required=False,
              widget=forms.Textarea(
                # rows and colums of the textarea
                attrs={ rows : 4,  cols : 40}))
    

#LOGIN
class LoginForm(forms.Form):
    username = forms.CharField(max_length=65)
    password = forms.CharField(max_length=65, widget=forms.PasswordInput)
问题回答

暂无回答




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签