Django 表单不适用于 DigitalOcean 服务器

Django forms not working on DigitalOcean Server

嗨,我最近一直在尝试在 DigitalOcean Ubuntu 16.4 服务器上部署一个 Django 网络应用程序,并且最终能够使用 uWSGI、nginx 加载视图,并让我们加密以实现安全连接.我唯一的问题是:有一些视图依赖于提交 django 表单来根据与用户的距离检索对象(视图中的 GeoDjango 查询)。有问题的表格如下所示:

<form method= 'get' action="/foo/">{% csrf_token %}
        <input  id='latload'  type= 'number' step='any' value='0' name='latitude' style="display:none">
        <input  id='lonload'  type= 'number' step='any' value='0' name='longitude' style="display:none">




    <p id= 'walltext' >Here you can listen to the sounds in your area. To use your current location, click 
    </p>


    <input class="btn btn-success" type='submit' id='submit' value='here' style="color:#1d3b77; font-size: 25px; width: 100%;" disabled />
</form>

它从之前的 Javascript getLocation() 函数中获取纬度和经度,然后通过表单传递给 /foo/ 视图,该表单按距离查询对象 (GeoDjango),看起来像这样:

def fetch_places_loc(request):
    lat= request.GET['latitude']
    lon= request.GET['longitude']
    finder_location = Point(float(lon),float(lat))

    nearby= Places.objects.filter(
        location__distance_lte=(
            finder_location,
            D(km=40))).distance(finder_location).order_by('distance').order_by('-rating__average')[:10]
    context= {
        'object_listboy': nearby,
        'title': 'wall',

    }
    return render(request, 'location/wall.html', context)

现在,在开发服务器上,它们一起工作,return最近的 10 个对象。在 Git 将项目克隆到 DigitalOcean 服务器并配置 uWSGI、NGINX 并使用 let's encrypt 保护连接后,视图没有 return 任何结果。它重定向到 "wall" 页面,列表中没有任何对象。我在浏览器控制台中没有收到任何类型的错误,并且所有 javascript 都正常工作(returns lat and long with console.log(),并将其放入Django 形式)。任何人都知道发生了什么事?我已经在网站上工作了一段时间,但在接近完成时遇到了麻烦。我的直觉指向可能不正确的 nginx 服务器配置或其他东西。如果您想查看任何配置,请告诉我。

如果您在请求中没有得到 latitudelongitude,那么代码会像您所写的那样抛出错误 - request.GET['latitude']

所以,我猜查询没有返回任何结果。您可以通过在服务器上使用 django shell 然后使用某些值 运行 数据库查询来调试它。

un display:none 并检查填写的表格中是否有一些数据 javascript,我很确定你必须允许站点对你进行地理定位