質問編集履歴
2
試したことの追加
    
        title	
    CHANGED
    
    | 
         
            File without changes
         
     | 
    
        body	
    CHANGED
    
    | 
         @@ -126,6 +126,4 @@ 
     | 
|
| 
       126 
126 
     | 
    
         
             
            ##### 上記の詳細・結果
         
     | 
| 
       127 
127 
     | 
    
         
             
            様々な実装例を確認して変更を施した。
         
     | 
| 
       128 
128 
     | 
    
         
             
            request.methodの判定をしているif文の中身をどのようにすればよいのか調べ、create_route関数内を成功している事例に近づけたが、結果は変わらなかった。
         
     | 
| 
       129 
     | 
    
         
            -
             
     | 
| 
       130 
     | 
    
         
            -
            ### 補足
         
     | 
| 
       131 
     | 
    
         
            -
             
     | 
| 
      
 129 
     | 
    
         
            +
            いろいろ試してみた結果、フォームは正しく機能しているが、そのフォームの中身がデータベースに反映されていないことが原因だと考えられる。
         
     | 
1
文書修正
    
        title	
    CHANGED
    
    | 
         
            File without changes
         
     | 
    
        body	
    CHANGED
    
    | 
         @@ -27,7 +27,7 @@ 
     | 
|
| 
       27 
27 
     | 
    
         | 
| 
       28 
28 
     | 
    
         
             
            ```forms.py
         
     | 
| 
       29 
29 
     | 
    
         
             
            from django import forms
         
     | 
| 
       30 
     | 
    
         
            -
            from  
     | 
| 
      
 30 
     | 
    
         
            +
            from my_app.models import Spot
         
     | 
| 
       31 
31 
     | 
    
         | 
| 
       32 
32 
     | 
    
         
             
            class PurposeForm(forms.ModelForm):
         
     | 
| 
       33 
33 
     | 
    
         
             
                class Meta():
         
     | 
| 
         @@ -39,10 +39,10 @@ 
     | 
|
| 
       39 
39 
     | 
    
         
             
            ```views.py
         
     | 
| 
       40 
40 
     | 
    
         
             
            from django.shortcuts import get_object_or_404, redirect, render
         
     | 
| 
       41 
41 
     | 
    
         | 
| 
       42 
     | 
    
         
            -
            from  
     | 
| 
      
 42 
     | 
    
         
            +
            from my_app.models import Spot
         
     | 
| 
       43 
43 
     | 
    
         
             
            from . import forms
         
     | 
| 
       44 
44 
     | 
    
         | 
| 
       45 
     | 
    
         
            -
            from  
     | 
| 
      
 45 
     | 
    
         
            +
            from myproject.routesearch.routesearch import routesearch
         
     | 
| 
       46 
46 
     | 
    
         | 
| 
       47 
47 
     | 
    
         | 
| 
       48 
48 
     | 
    
         
             
            def create_route(request):
         
     | 
| 
         @@ -58,16 +58,16 @@ 
     | 
|
| 
       58 
58 
     | 
    
         | 
| 
       59 
59 
     | 
    
         
             
                        spot = form.save(commit=False)
         
     | 
| 
       60 
60 
     | 
    
         
             
                        spot.save()
         
     | 
| 
       61 
     | 
    
         
            -
                    return redirect(' 
     | 
| 
      
 61 
     | 
    
         
            +
                    return redirect('my_app/routesearch.html')
         
     | 
| 
       62 
62 
     | 
    
         | 
| 
       63 
63 
     | 
    
         
             
                else:
         
     | 
| 
       64 
64 
     | 
    
         
             
                    form = forms.PurposeForm(instance=spot)
         
     | 
| 
       65 
     | 
    
         
            -
                    return render(request, " 
     | 
| 
      
 65 
     | 
    
         
            +
                    return render(request, "my_app/home.html", {'form': form})
         
     | 
| 
       66 
66 
     | 
    
         | 
| 
       67 
67 
     | 
    
         | 
| 
       68 
68 
     | 
    
         
             
            def display_route(request):
         
     | 
| 
       69 
69 
     | 
    
         
             
                data = Spot.objects.all()
         
     | 
| 
       70 
     | 
    
         
            -
                return render(request, ' 
     | 
| 
      
 70 
     | 
    
         
            +
                return render(request, 'my_app/routesearch.html', {'data': data})
         
     | 
| 
       71 
71 
     | 
    
         | 
| 
       72 
72 
     | 
    
         
             
            ```
         
     | 
| 
       73 
73 
     | 
    
         | 
| 
         @@ -77,16 +77,16 @@ 
     | 
|
| 
       77 
77 
     | 
    
         
             
            <html>
         
     | 
| 
       78 
78 
     | 
    
         
             
                <head>
         
     | 
| 
       79 
79 
     | 
    
         
             
                    <meta charset="utf-8" />
         
     | 
| 
       80 
     | 
    
         
            -
                    <title> 
     | 
| 
      
 80 
     | 
    
         
            +
                    <title>My App</title>
         
     | 
| 
       81 
81 
     | 
    
         
             
                </head>
         
     | 
| 
       82 
82 
     | 
    
         | 
| 
       83 
83 
     | 
    
         
             
                <body>
         
     | 
| 
       84 
     | 
    
         
            -
                    <h1> 
     | 
| 
      
 84 
     | 
    
         
            +
                    <h1>My App</h1>
         
     | 
| 
       85 
85 
     | 
    
         
             
                    <p>
         
     | 
| 
       86 
86 
     | 
    
         
             
                        Input purpose
         
     | 
| 
       87 
87 
     | 
    
         
             
                    </p>
         
     | 
| 
       88 
88 
     | 
    
         
             
                    <form
         
     | 
| 
       89 
     | 
    
         
            -
                        action="{% url ' 
     | 
| 
      
 89 
     | 
    
         
            +
                        action="{% url 'my_app:routesearch' %}"
         
     | 
| 
       90 
90 
     | 
    
         
             
                        method="post"
         
     | 
| 
       91 
91 
     | 
    
         
             
                    >
         
     | 
| 
       92 
92 
     | 
    
         
             
                        {{ form.as_p }}
         
     | 
| 
         @@ -103,7 +103,7 @@ 
     | 
|
| 
       103 
103 
     | 
    
         
             
            <html>
         
     | 
| 
       104 
104 
     | 
    
         
             
                <head>
         
     | 
| 
       105 
105 
     | 
    
         
             
                    <meta charset="utf-8" />
         
     | 
| 
       106 
     | 
    
         
            -
                    <title> 
     | 
| 
      
 106 
     | 
    
         
            +
                    <title>M App</title>
         
     | 
| 
       107 
107 
     | 
    
         
             
                </head>
         
     | 
| 
       108 
108 
     | 
    
         | 
| 
       109 
109 
     | 
    
         
             
                <body>
         
     |