我在我的模板中有一个用于搜索的表单。我没有为它创建任何表单类。是否可以在视图中访问表单数据,或者我应该为其创建表单类。
<form class="navbar-form" role="search" action="{% url 'my_url_name' %}" method="get">
<div class="input-group add-on">
<input class="form-control" placeholder="search" name="srch-term" id="srch-term" type="text">
<div class="input-group-btn">
<button class="btn btn-default" type="submit"><i class="glyphicon glyphicon-search"></i></button>
</div>
</div>
</form>
我使用此表单作为其样式,我无法使用Form类
创建此样式答案 0 :(得分:0)
您可以在视图中的request.GET
(或request.POST
,如果它是一个帖子请求)词典中访问表单数据。例如:
srch_term = request.GET.get('srch-term')
答案 1 :(得分:0)
您可以使用请求获得的QueryDict对象:
import { NgModule } from '@angular/core';
import { IonicApp, IonicModule } from 'ionic-angular';
import { Camera } from 'ionic-native';
import { Http, XSRFStrategy, CookieXSRFStrategy } from '@angular/http';
import { Storage } from '@ionic/storage';
import { FormsModule } from '@angular/forms';
import { MyApp } from './app.component';
import { AboutPage } from '../pages/about/about';
import { HomePage } from '../pages/home/home';
import { TabsPage } from '../pages/tabs/tabs';
import { LoginPage } from '../pages/login/login';
import { PhotoPage } from '../pages/photo/photo';
import { AboutPage } from '../pages/about/about';
import { GalleryPage } from '../pages/gallery/gallery';
import { SubmittedPage } from '../pages/submitted/submitted';
import { PhotoPage } from '../pages/photo/photo';
import { ResetPasswordPage } from '../pages/reset-password/reset-password';
import { SignupPage } from '../pages/signup/signup';
import { DjangoAuth } from '../providers/djangoAuth';
import { ImageData } from '../providers/imageData';
@NgModule({
declarations: [
MyApp,
AboutPage,
HomePage,
TabsPage,
LoginPage,
PhotoPage,
GalleryPage,
SubmittedPage,
ResetPasswordPage,
SignupPage
],
imports: [
IonicModule.forRoot(MyApp, [
Http,
DjangoAuth,
ImageData,
FormsModule,
{provide:XSRFStrategy, useValue: new CookieXSRFStrategy('csrftoken', 'X-CSRFToken')}])
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
AboutPage,
HomePage,
TabsPage,
LoginPage,
PhotoPage,
GalleryPage,
SubmittedPage,
ResetPasswordPage,
SignupPage
],
providers: [
DjangoAuth,
ImageData,
Storage,
Camera
]
})
export class AppModule {}
但请注意:没有验证工具可以确保您收到的数据格式正确。