2011-02-24 49 views
0

在我的項目中,我對用戶有3個操作,我的任務。是我怎樣才能將它們路由django在view.py中獲取數據和路由

我的代碼:

def featuresave(request): 
layerId = request.POST.get("layid") 
features = request.POST.get("feat") 

if features == 'POINT': #(it includes Point string and coordinate as "POINT(38 39)"  
    als = Point() 
    als.layer = Layers.objects.get(id = layerId) 
    als.feature = features 
    als.save() 

if feature == 'LINESTRING': #(it includes Linestring string and coordinate) 
    als = Line() 
    als.layer = Layers.objects.get(id = layerId) 
    als.feature = feature 
    als.save() 

if feature == 'POLYGON': #(it includes Linestring string and coordinate) 
    als = Poly() 
    als.layer = Layers.objects.get(id = layerId) 
    als.feature = feature 
    als.save() 

return HttpResponse("OK") 

感謝您的幫助

+0

您的代碼現在是否存在問題? (減去僞代碼) – 2011-02-24 13:02:27

+0

注意你做了features = request.POST,並且在第二次和第三次測試中比較了'feature'。這是問題嗎?你不清楚。始終剪切並粘貼您的代碼,以避免在拼音中出現拼寫錯誤。 – Spacedman 2011-02-24 13:09:08

+0

它不通過數據庫保存線模型中的線串 – aragon 2011-02-24 13:23:39

回答

0

在您的意見看,假設你是在談論你的request.POST.feat包括:

#(it includes Point string and coordinate as "POINT(38 39)" 
#(it includes Linestring string and coordinate) 
#(it includes Linestring string and coordinate) 

和評論前攀比......你不會得到匹配...

您的比較可能應該類似於

if feature.find('POINT') != -1: 
    #do something 
elif feature.find('LINESTRING') != -1: 
    #do something 
elif feature.find('POLYGON') != -1: 
    #do something