1👍
Django ModelAdmin
allows you to define custom view in it. So move your view code to the ModelAdmin
and override the get_urls()
method:
class MyModelAdmin(admin.ModelAdmin):
def get_urls(self):
urls = super(MyModelAdmin, self).get_urls()
my_urls = patterns('',
(r'^test_view/$', self.admin_site.admin_view(self.test_view))
)
return my_urls + urls
def test_view(self, request):
form = TestForm(request.POST or None)
...
To use the admin layout in your test.html
template extend it from admin/base_site.html
:
{% extends "admin/base_site.html" %}
{% block title %}My test upload{% endblock %}
{% block content %}
<form action="" method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Upload" />
</form>
{% endblock %}
Source:stackexchange.com