Error Noreversematch

Asked

Viewed 904 times

0

Hello, I have the following error in an application in Django.

Noreversematch at /Row/Details/2 Reverse for 'get-weatherdata' with keyword Arguments '{'rowId': 1, 'sensorId': 1}' not found. 1 Pattern(s) tried: ['api/weatherData/$'] Request Method: GET Request URL: http://localhost:8000/Row/Details/2 Django Version: 2.2.5 Exception Type: Noreversematch Exception Value: Reverse for get-weatherdata' with keyword Arguments '{'rowId': 1, 'sensorId': 1}' not found. 1 Pattern(s) tried: ['api/weatherData/$']

I need to pass two identifiers as a parameter for the/weatherdata api. I don’t know if I am doing it correctly, but it follows the other codes

py views.

def get_weatherData(request, rowId, sensorId):
    weatherData = WeatherData.objects.filter(row_id=rowId, sensor_id=sensorId)

py.

url(r'^api/weatherData/$', get_weatherData, name='get-weatherdata'),

index.html

<script>
{% block jquery %}
var endpoint = '/api/weatherData/'
var defaultData = []
var labels = [];
$.ajax({
    method: "GET",
    url: endpoint,
    success: function(data){
        labels = data.date
        defaultData = data.value
        setChart(labels, defaultData)
    },
    error: function(error_data){
        console.log("error")
        console.log(error_data)
    }
})
{% endblock %}
</script>
<div class="container" url-endpoint='{% url "get-weatherdata" rowId=1 sensorId=1 %}'>

1 answer

1

You are sending parameters on template and also receiving them in view but there is no route at urls which satisfies this condition, thus adding the parameters to it.

    url(
        r'^api/weatherData/([0-9]+)/([0-9]+)/$',
        get_weatherData,
        name='get-weatherdata'
    ),

In version 2.x of Django was introduced to path() which is much clearer to define URL syntax than regex of url().

Browser other questions tagged

You are not signed in. Login or sign up in order to post.