我可以添加與Django的AJAX代碼? 我創建了一個簡單的註冊表格,有5個字段。我希望顯示不同頁面中的每個字段,但在一個窗口中顯示。這意味着通過使用下一個按鈕5頁要顯示在一個窗口中。同時我希望每個頁面的所有內容都添加到我的數據庫中。這可能在Django與阿賈克斯..ajax與Django的形式
我的代碼如下:
#view
from django.shortcuts import render_to_response
from registration.models import UserDetails
from forms import UserForm
from django import forms
from django.template import RequestContext
from django.http import HttpResponseRedirect
def user_details(request):
if request.method == 'POST':
form = UserForm(request.POST)
if form.is_valid():
form.save()
else:
form = UserForm()
return render_to_response("career.html", {"form": form},context_instance=RequestContext(request))
#form
from django import forms
from registration.models import UserDetails
class UserForm(forms.ModelForm):
pass
class Meta:
model = UserDetails
#model
from django.db import models
class UserDetails(models.Model):
fname=models.CharField(max_length=20)
lname=models.CharField(max_length=20)
email = models.EmailField()
address = models.CharField(max_length=50)
country = models.CharField(max_length=20)
def __unicode__(self):
return self.fname
return self.lname
return self.email
return self.address
return self.country
#url
from django.conf.urls.defaults import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
url(r'^registration/$', 'registration.views.user_details', name='user_details'),
url(r'^admin/', include(admin.site.urls)),
)
# template
<form enctype="multipart/form-data" method="post">{% csrf_token %}
{{ form.as_p }}
<input type="submit" ....>
</form>
請重寫你的問題。我不知道你在問什麼。 – 2012-01-30 11:39:42
[形式和django中的ajax]可能的重複(http://stackoverflow.com/questions/9063651/forms-and-ajax-in-django) – 2012-01-30 13:55:59
請不要發佈同一個問題的多個版本。 – 2012-01-30 15:33:22