In views:
def article_add(request):
print request.user, " is adding an article"
if request.method == "POST":
web_url = request.POST['web_url']
Uploadarticle(web_url)
return redirect('myapp:index')
In html:
<form class="navbar-form navbar-right" role="form" method="post" action="{% url 'myapp:article_add' %}" enctype="multipart/form-data">
{% csrf_token %}
<div class="form-group">
<div class="col-sm-10">
<input id="article_url" name="web_url" type="text">
</div>
</div>
<button type="submit" class="btn btn-default"> + </button>
</form>
In url.py:
app_name = 'myapp'
urlpatterns = [
url(r'^$', views.IndexView.as_view(), name='index'),
url(r'^$', views.article_add, name='article_add'),
]
What i'm trying to do here is to pass the url value through html to view, call the function to upload the database, redirect the user to the same home page as refresh then the newly added item will show up.
Somehow everytime I submit I got a blank page, in terminal I got an errors says:
Method Not Allowed (POST): /
"POST / HTTP/1.1" 405 0