django-leaflet
django-leaflet copied to clipboard
A map in a form is not shown
I try to add my form into an admin panel. I already have django-leaflet and it works normal via LeafletGeoAdmin.
But I need to add my form without a model.
I define a form:
from leaflet.forms.fields import PointField as PointFieldLL
from django import forms
class MarkerPostForm(forms.Form):
user_from = forms.CharField(label="User, marker's owner")
content = PointFieldLL()
A view:
@csrf_exempt
@alt_login_required
def post_marker_from_admin(request, v=None, user=None):
if user.is_staff is False:
return response_message('You are not admin', 403)
if request.method == 'POST':
form = MarkerPostForm(request.POST)
if form.is_valid():
content = form.cleaned_data['content']
user_from = form.cleaned_data['user_from']
data = { "us_from": user_from,
"marker": content}
return response_json(data, 200)
else:
form = MarkerPostForm(initial={'user_from': 'spont'})
return render(request, 'send_message_from_admin.html', {'form': form})
An extension of admin template:
{% extends "admin/base_site.html" %}
{% load i18n admin_static %}
{% load static %}
{% load leaflet_tags %}
{% block title %}Post marker{% endblock %}
{% block extrahead %}
{% leaflet_js plugins="ALL" %}
{% leaflet_css plugins="ALL" %}
{% endblock %}
{% block content %}
<!-- <body> -->
<form action="{% url 'manage_app.views_manage_app.post_marker_from_admin' v='v1.0' %}" method="post">
{% csrf_token %}
{{ form }}
<input type="submit" value="Post marker" />
</form>
<!-- </body> -->
{% endblock %}
<!-- </html> -->
Result: I see my form, but leaflet map is not shown.
Could you tell me what I did wrong?
Any error in the console?