0

My django main site urls

from django.contrib import admin
from django.urls import path,include

urlpatterns = [

    path('ways/', include('ways.urls')),
    path('admin/', admin.site.urls),

app url

urlpatterns = [

    path('newWay/', views.newWay, name='newWay'),
    path('waySolved/', views.update_way, name='update_way'),


]

project structure Project structure

But whenever i hit http://localhost:8000/ways/waySolved/ it says Not Found: /ways/waySolved/ but http://localhost:8000/ways/newWay/ works perfectly. In views i have both functions. update_way

def update_way(request):
    way_id= request.GET.get('way_id', None)
    token=request.GET.get('token', None)

    if way_id is not None and token is not None:
        token = token.replace("\"", "")

        community_osm_cur.execute("""SELECT  latitude ,longitude from (SELECT * from (SELECT  
            latitude,longitude,id from  current_nodes where id in (Select node_id from 
            current_way_nodes where way_id='%s' ORDER BY  sequence_id asc )) AS temp1
            Inner join
            (Select node_id,sequence_id from current_way_nodes where way_id='%s' 
            ORDER BY  sequence_id asc ) As temp2 on temp1.id=temp2.node_id
            order by sequence_id asc) As temp3""", ((int)(way_id), (int)(way_id),))
        nodes_list = community_osm_cur.fetchall()

        coords = []
        if len(nodes_list)>0:

            for node in nodes_list:
                lat = node[0] / 10000000
                lng = node[1] / 10000000
                coords.append([lat, lng])

            position_hash = hashlib.sha3_256(json.dumps(coords).encode()).hexdigest()
            community_osm_cur.execute("select user_id from oauth_tokens where secret = %s", (token,))
            id = community_osm_cur.fetchone()[0]



            updated_way_cur.execute("""INSERT INTO updated_ways (way_id,node_hash) values 
              (%s,%s) on conflict(way_id)  do update set node_hash=%s""",
              (way_id,position_hash,position_hash,))
            updated_way_cur.execute("Delete from distribution where user_id=%s and  id = %s ",(id,way_id,))
            updated_way_con.commit()
            return HttpResponse(status=200)
    return HttpResponse(status=404)
enigma
  • 45
  • 1
  • 7

1 Answers1

0

This looks like an issue in your view, not your URL patterns.

You are accessing /ways/waySolved/?way_id=13232323, and the first two lines are.

def update_way(request):
    way_id= request.GET.get('way_id', None)
    token=request.GET.get('token', None)

There is no token in the querystring, so you'll have way_id=13232323 and token=None.

Then your code does:

if way_id is not None and token is not None:
    ...
return HttpResponse(status=404)

Since token is None, the view jumps to the end, so the 404 response is expected.

Alasdair
  • 298,606
  • 55
  • 578
  • 516
  • but server is printing** Not Found: /ways/waySolved/** so may be it has not reached there – enigma Apr 27 '18 at 13:48
  • I have tested it with dummy token but the response is same ** Not Found: /ways/waySolved/ "GET /ways/waySolved/?way_id=13232323&token=646464 HTTP/1.1" 404 0** – enigma Apr 27 '18 at 13:50
  • You haven't shown the full error message so I can't tell for sure, but it looks as if it's an issue in the `update_way` view, and not with your URL patterns. You need to add some printing/logging to the `update_way` to see what code is executing. Even if `token` is not None, there are other code paths that will end with `return HttpResponse(status=404)`. – Alasdair Apr 27 '18 at 13:53
  • Actually it is not giving any error its just printing and its all that the code prints – enigma Apr 27 '18 at 13:57
  • If the 404 was a problem with your URL patterns, then you'd get the yellow debug page in your browser when running with `DEBUG=True`. If the 404 is coming from the `return HttpResponse(status=404)` line, then you won't get that 404 page, I was mistaken about that. My suggestion is the same as before -- add printing/logging to your view to work out why it reaches `HttpResponse(status=404)`. – Alasdair Apr 27 '18 at 14:02