2016-06-06 5 views
0

다소 바보 같은 질문이 있습니다. 이미 사용자 ID가있는 경우
또는
로그인 (버튼 제출)HTML WebPy multilpe forms

는 우편 번호를 입력 :

나는 응용 프로그램을 시도하고 그것에 두 가지 형태를하고있다.

내 코드 (파이썬은 web.py 프레임 워크를 사용함)에 두 개의 def POST(self)이 있지만 첫 번째 양식과 두 번째 로그인 양식 호출은 무엇입니까?

나는 혼란 스럽다. 이제 내 친구는 html이 두 가지 다른 형태를 가질 수 없다고 알려줍니다.

여기 코드와 양식이 불완전합니다. 더 많은 데이터를 얻고 db 스키마를 작성하기 전에 메소드가 잘 실행되도록하려고합니다.

import web 
from web import form 

render = web.template.render('templates/') 

urls = (
    '/', 'index' 
) 

myform = form.Form(
    form.Textbox("Zip Code", 
       form.regexp('^\d{5}$', 'Not a zip code'), 
       description='Enter a 5 digit zip code', 
       maxlength = '5'), 
) 

myloginform = form.Form(
    form.Textbox("Username", 
         form.regexp('^[^<>\s\@]+(\@[^<>\s\@]+(\.[^<>\s\@]+)+)$', 'Invalid username'), 
         description='Enter your username'), 
) 

class index: 
    def __init__(self): ** i still dont know wtf this does.. 
     pass 

    def GET(self): 
     form = myform() 
     myloginform1 = myloginform() 
     return render.index(form,myloginform1) 

    def POST(self): 
     form = myform() 
     if not form.validates(): 
      return render.index(form) 
     else: 
      return "The zip code you are located is: %s" % (form['Zip Code'].value) 

    def POST(self): 
     myloginform1 = myloginform() 
     if not myloginform1.validates(): 
      return render.index(myloginform1) 
     else: 
      return "Welcome %s" % (myloginform1['Username'].value) 

class testfunc: 
    def GET(self): 
     return "Test function returning!" 

if __name__ == "__main__": 
    app = web.application(urls, globals()) 
    app.run() 

index.html

$def with (form, myloginform1) 

<html> 
<head><title>8reps Welcome.. </title></head> 
<body> 

<h3>Hi</h3> 

<p> Lets find some results in your area.. </p> 
<form name="main" method="post"> 
    $if not form.valid: <p class="error">Try again...</p> 
    $:form.render() 
    <input type="submit" /> </form> 

<p> Already registered? Login as a user..</p> 
<form name="login" method="post"> 
    $if not myloginform1.valid: <p class="error">Try again..</p> 
    $:myloginform1.render() 
    <input type="submit" />Login</form> 
</form> 
</body> 
</html> 

감사합니다 아래에!

답변

0

페이지에 원하는만큼 많은 양식이있을 수 있지만 유일한 문제는 어떻게 처리 할 것인가입니다.

  1. 두 개의 백엔드 예 :

    2 가지 방법이 있습니다 /login/zip 양식 게시물을 처리하는 - 양식 태그에 제대로

  2. 단일 /index 당신이 두 형태를 처리 할 수있는 직접 게시물 action 속성을 추가해야합니다,하지만 당신은 게시 된 양식을 인식 할 필요가, 예를 들어,

    <input name="submit" type="submit" value="Zip" /> 
    

    두 번째 양식 :

    <input name="submit" type="submit" value="Login" /> 
    

    다음 당신이 알고있는 것 확인하여 게시 된 양식을 일부 지정된 필드의 존재에 의해 (당신은 이름은 같지만 서로 다른 값으로 입력을 제출 사용할 수 있습니다 전송의 값은 필드 "제출". 확실히

, 당신은이 방법은 클래스 정의에 같은 이름을 재치 할 수 없습니다.

+0

Jerzyk ... 자세한 답변을 주셔서 감사합니다. – ranjitcool