我想给一些人发链接让我们说:
http://www.example.com/form/?q=example@me.com
如果他们单击该链接,它将转到 /form/ 页面,其中包含多个字段的表单。
我想用那个 q 字符串预先填充它,它会填写那个“电子邮件”输入
在字符串“example@me.com”中具有指定电子邮件的字段。
网站是用 Django 完成的,想问一下最好的方法是什么。
我应该使用 JS、Jquery、Django 吗?不知道从哪里开始。
想要这样的东西:
http://support.unbounce.com/entries/307658-Can-I-pre-populate-a-form-with-URL-parameters-VIDEO-
但在我的网站上。有人可以提供简单的表格和示例吗?
谢谢
模型.py
from django.db import models
class Example(models.Model):
username = models.CharField(max_length=200, blank=True)
email = models.CharField(max_length=200)
image = models.ImageField(upload_to='profiles', blank=True)
text = models.CharField(max_length=200, blank=True)
表格.py
from django import forms
from models import Example
class ExampleForm(forms.ModelForm):
class Meta:
model = Example
视图.py
from django import forms
from models import Example
from forms import ExampleForm
from django.template import RequestContext, Context
from django.core.context_processors import csrf
from django.shortcuts import render_to_response
from django.shortcuts import render_to_response, get_object_or_404
from django import http
import os
import json
from django.http import HttpResponse
from django.http import HttpResponseRedirect
from django.conf import settings
def index(request):
if request.method == "POST":
form = ExampleForm(request.POST, request.FILES)
if form.is_valid():
form.save()
return http.HttpResponseRedirect('/success/')
else:
form = ExampleForm()
return render_to_response('index.html', {'title': 'Example Form', 'form': form},context_instance=RequestContext(request))
网址.py
from django.conf.urls import patterns, include, url
from django.conf import settings
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^$', 'signup.views.index', name='index'),
url(r'^admin/', include(admin.site.urls)),
)
索引模板
<form id='add_cat' method='post' enctype="multipart/form-data">{% csrf_token %}
<input id="id_username" maxlength="200" name="username" type="text" placeholder="username">
<input id="id_email" maxlength="200" name="email" type="text" >
<input id="id_picture" maxlength="200" name="picture" type="text">
<textarea id="id_text" row="3" name="first_text" placeholder="Type something…"></textarea>
<input id="add_cat_btn" type='submit' value="save">
</form>