Reputation: 1
Python 3.8.5 Django 3.1.2
I created a Django Project. I have an HTML page created with a button. I need to assign the following urlpattern to that HTML button...
path('', views.output, name='output'),
That URLpattern is linked to a function called 'output' which runs successfully on it's own. I'm using the following HTML code to assign that function to my HTML button...
<button onclick="Location.href='{% url 'output' %}'"> Enter </button>
This does not work. I cannot get this button to run my function.
Does anyone know how to assign this function successfully?
Here is my code in my urls.py file...
from django.contrib import admin
from django.urls import path, include
from myapp import views
urlpatterns = [
path('app/', include('myapp.urls')),
path('admin/', admin.site.urls),
path('', views.output, name='output'),
]
Upvotes: 0
Views: 236
Reputation: 90
You can create a button using a tags with bootstrap. It will be like this
<a href="{% url 'output'%}" class="btn btn-primary">Enter</a>
If you were not using bootstrap you can style it.
HTML
<a href="{% url 'output'%}" class="button">Enter</a>
CSS
a.button {
-webkit-appearance: button;
-moz-appearance: button;
appearance: button;
text-decoration: none;
color: initial;}
Upvotes: 1