"Page not found (404)" when clicking on follow or unfollow button - html

urls.py
"""stratinum URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/1.10/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.conf.urls import url, include
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import url, include
from django.contrib import admin
from imagec import views as imagec_views
from contact import views as contact_views
from django.conf.urls.static import static
from django.conf import settings
from django.core.urlresolvers import reverse
admin.autodiscover()
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^$', imagec_views.home, name='home'),
url(r'^about/$', imagec_views.about, name='about'),
url(r'^detail/$', imagec_views.detail, name='detail'),
url(r'^profile/$', imagec_views.userProfile, name='profile'),
url(r'^create_form/$', imagec_views.create_form, name='create_form'),
url(r'^contact/$', contact_views.contact, name='contact'),
url(r'^userProfile/$', contact_views.contact, name='userProfile'),
url(r'^accounts/', include('allauth.urls')),
url('', include('social.apps.django_app.urls', namespace='social')),
url('', include('django.contrib.auth.urls', namespace='auth')),
url(r'^$', imagec_views.ListaFollow, name="lista_follow"),
url(r'^add_follow/(?P<id>\d{1,})/$', imagec_views.AddFollow, name='add_follow'),
url(r'^remove_follow/(?P<id>\d{1,})/$', imagec_views.RemoveFollow, name='remove_follow')
]
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
views.py
from django.contrib.auth.decorators import login_required
from django.shortcuts import render
from django.conf import settings
from django.core.files.storage import FileSystemStorage
from django.core.urlresolvers import reverse
from django.shortcuts import render, get_object_or_404
from .forms import AlbumForm
from .models import Album
from django.http import HttpResponse,HttpResponseForbidden
IMAGE_FILE_TYPES = ['png', 'jpg', 'jpeg']
# Create your views here.
def home(request):
context = {}
template = 'home.html'
return render(request, template, context)
def about(request):
context = {}
template = 'about.html'
return render(request, template, context)
#login_required()
def userProfile(request):
user = request.user
context = {'user': user}
template = 'profile.html'
return render(request, template, context)
def create_form(request):
form = AlbumForm(request.POST or None, request.FILES or None)
if form.is_valid():
album = form.save(commit=False)
album.user = request.user
album.image= request.FILES['image']
file_type = album.image.url.split('.')[-1]
file_type = file_type.lower()
if file_type not in IMAGE_FILE_TYPES:
context = {
'album': album,
'form': form,
'error_message': 'Image file must be PNG, JPG, or JPEG',
}
return render(request, 'detail.html', context)
album.save()
return render(request, 'create_form.html', {'album': album})
context = {
"form": form,
}
return render(request, 'create_form.html', context)
def detail(request):
user = request.user
#album = get_object_or_404(Album, pk=id)
return render(request, 'detail.html', {'user': user})
from django.shortcuts import render, redirect
from .models import MyUser
from django.views.generic import TemplateView,View
from django.db.models import Q
from django.core.urlresolvers import reverse
from . import models
#from imagec.models import User
from django.contrib.auth.models import Permission, User
class ListaFollow(TemplateView):
template_name = 'lista_follow.html'
def get_context_data(self,**kwargs):
context = super(ListaFollow,self).get_context_data(**kwargs)
context['all'] = MyUser.objects.all()
context['me'] = User.objects.get(username=self.request.user)
context['notme'] = MyUser.objects.filter(follow__username=self.request.user)
context['notfollow'] = MyUser.objects.filter(~Q(follow__username=self.request.user))
return context
class AddFollow(View):
def get(self,request, id):
me=models.MyUser.objects.get(username=request.user)
followed = models.MyUser.objects.get(id=id) #el wey
me.follow.add(followed)
return redirect(reverse('imagec/about.html'))
class RemoveFollow(View):
def get(self,request, id):
me=models.MyUser.objects.get(username=request.user) #instancia del usuario con el id que quiero crear
followed = models.MyUser.objects.get(id=id)
me.follow.remove(followed) #creo el usuario con mi nombre y la relacion
return redirect(reverse('imagec/about.html'))
models.py
from __future__ import unicode_literals
from django.contrib.auth.models import Permission, User
from django.db import models
# Create your models here.
class profile(models.Model):
name = models.CharField(max_length=120)
description = models.TextField(default='description default text')
def __unicode__(self):
return self.name
class Album(models.Model):
user = models.ForeignKey(User, default=1)
image = models.FileField()
class MyUser(models.Model):
user = models.ForeignKey(User)
username = models.CharField(max_length=200)
follow = models.ManyToManyField('self', blank=True)
def __unicode__(self):
return self.username
about.html
{% extends 'base.html' %}
{% block content %}
<body>
<div class="container">
<h1>Profile</h1>
<p>Username: {{ user }}</p>
<p>Email: {{ user.email }}</p>
<p><input type="submit" value="Upload"/></p>
</div>
<table>
<tr>
<th colspan="3"> # {{ user }}</th>
</tr>
<tr>
<td colspan="3">
<span> Follows </span>
</td>
</tr>
<td>{{follow}} <a href="add_follow/{{user.id}}">
<button>Follow</button></a></td>
<td>{{follow}} <a href="remove_follow/{{user.id}}">
<button>Unfollow</button></a></td>
</a>
<tr>
<td colspan="3">
<span> Unfollows </span>
</td>
</tr>
</table>
</body>
{% endblock %}
When I run this code I will get error as:
"Not Found: /about/add_follow/1
[22/Apr/2017 07:26:25] "GET /about/add_follow/1 HTTP/1.1" 404 6063"
in the terminal.

This happening because you are using relative url to create a link to the follow/unfollow page. To fix this, you can either make it an absolute url or use django's url reverser.
Making the link absolute:
<td>{{follow}} <a href="/add_follow/{{user.id}}">
<button>Follow</button></a></td>
<td>{{follow}} <a href="/remove_follow/{{user.id}}">
<button>Unfollow</button></a></td>
Making use of the url tempalte tag
<td>{{follow}} <a href="{% url 'add_follow' id=user.id %}">
<button>Follow</button></a></td>
<td>{{follow}} <a href="{% url 'remove_follow' id=user.id %}">
<button>Unfollow</button></a></td>
Read about Absolute and Relative urls

Related

Django override django.contrib.auth login process

views.py
from django.contrib import messages
from django.http import HttpResponse
from django.contrib.auth import authenticate, login
from django.contrib.auth.views import LoginView
from django.shortcuts import render
def index(request):
return render(request, 'index.html')
def templates(request):
return render(request, 'templates.html')
def information(request):
return render(request, 'information.html')
def custom_login(request):
if request.POST:
username = request.POST['username']
password = request.POST['password']
user = authenticate(username = username, password = password)
print("work")
if user is not None:
messages.success(request, 'Success')
login(request, user)
return HttpResponse('login')
#logout(request)
else:
messages.error(request, 'Invalid username or password')
print("error")
return HttpResponse('wrong username or password')
class CustomLoginView(LoginView):
print("check")
def form_valid(self):
custom_login(self.request)
urls.py
from django.contrib import admin
from django.urls import path, include
from ArtisticCode import views
urlpatterns = [
path('admin/', admin.site.urls),
path('accounts/login/', views.CustomLoginView.as_view(), name='login'),
path('accounts/', include('django.contrib.auth.urls')),
path('', views.index, name = 'index'),
path('templates/', views.templates, name = 'templates'),
path('information/', views.information, name = 'information'),
]
accounts/login.html
<form method="post" class="login">
{% csrf_token %}
<div class="login_input">
<img src="{% static 'img/bx_img1.png' %}" alt="image"/>
<input type="text" placeholder="Username" name="username" required/>
</div>
<div class="login_input">
<img src="{% static 'img/bx_img1.png' %}" alt="image"/>
<input type="password" placeholder="Password" name="password" required/>
</div>
<input type="submit" value="Send message"/>
{% if messages %}
{% for message in messages %}
<strong style="color:white;">{{ message }}</strong>
{% endfor %}
{% endif %}
</form>
The idea is to display a message in case of a wrong password, but I can't catch the post method correctly. From what I did past few days to try to make this, I found that I need to override the login. I think the function form_valid is the one that I need to override so I can handle the post method
setting.py
INSTALLED_APPS = [
'django.contrib.auth',
'django.contrib.messages',
]
MIDDLEWARE = [
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
]
The solution to the problem is to do everything yourself without using the ready-made functions, because the password and the name go to the same place, whether you write it yourself or use ready code. The idea from the beginning was that if I use the ready forms such as form.as _p I can't laugh at the style then there was no way to put notification for a wrong password from there I came to the conclusion that is writing everything yourself is best.
changes:
urls.py
from django.contrib import admin
from django.urls import path
from ArtisticCode import views
urlpatterns = [
path('admin/', admin.site.urls),
path('accounts/login/', views.login, name='login'),
path('', views.index, name = 'index'),
path('templates/', views.templates, name = 'templates'),
path('information/', views.information, name = 'information'),
]
views.py
from django.contrib import messages
from django.contrib.auth import authenticate, login
from django.shortcuts import render
def index(request):
return render(request, 'index.html')
def templates(request):
return render(request, 'templates.html')
def information(request):
return render(request, 'information.html')
def login(request):
if request.POST:
username = request.POST['username']
password = request.POST['password']
user = authenticate(username = username, password = password)
if user is not None:
messages.success(request, 'Success')
#login ...
else:
messages.error(request, 'Invalid username or password')
return render(request, 'registration/login.html')

NoReverseMatch at 'url' in Django, Reverse for 'my_app' not found. 'my_app' is not a valid view function or pattern name

I'm new to Django, and today when I tried to run a website with a database, I have encountered this error.
I have searched for all solutions on StackOverflow and Django documents, but I can not fix it.
This is the problem that similar to me, but it doesn't work.
I want to create a link that moves user from user.html in user to index.html in citizens
Here is my project structure. I'm sorry because I can't attach an image, so I will try to explain it in easiest way.
[MYPROJECT]
->manage.py
->citizens (folder)
-->templates (inside this folder I have citizen.html, index.html, layout.html)
-->admin.py
-->models.py
-->tests.py
-->urls.py
-->views.py
->myproject (folder)
-->setting.py
-->urls.py
-->etc that I think not important
->user (folder)
-->templates (inside this folder I have login.html, user.html, layout.html)
-->urls.py
-->views.py
-->etc that I think not important
As you can see, I have user.html inside templates folder of user, and index.html inside templates folder of citizens.
Here is my code:
index.html inside citizens
{% extends "citizens/layout.html" %}
{% block body %}
<h1>Hệ thống quản lý XNC</h1>
<table class="table">
<thead>
<tr>
<th scope="col">Số TT</th>
<th scope="col">Họ và tên công dân</th>
<th scope="col">Giới tính</th>
<th scope="col">Số Hộ chiếu</th>
<th scope="col">Chi tiết</th>
</tr>
</thead>
<tbody>
{% for citizen in citizens %}
<tr>
<th scope="row">{{ forloop.counter }}</th>
<td>{{ citizen.name }}</td>
<td>{{ citizen.sex }}</td>
<td>{{ citizen.sID }}</td>
<td>Truy cập</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}
user.html inside user
{% extends "users/layout.html" %}
{% block body %}
<h1>Chào mừng, {{ request.user.username }}</h1>
<ul>
<li>Username: {{request.user.username }}</li>
</ul>
Truy cập Cơ sở dữ liệu
{% endblock %}
urls.py inside citizens
from django.urls import path
from . import views
urlpatterns = [
path("", views.index, name="index"),
path("<int:citizen_id>", views.citizen, name="citizen"),
#path("<int:citizen_id>/passports", views.passport, name="passports")
]
views.py inside citizens
from django.shortcuts import render
from django.http import HttpResponseBadRequest, HttpResponseRedirect, Http404
from django.urls import reverse
from .models import Citizen
# Create your views here.
def index(request):
return render(request, "citizens/index.html", {
"citizens": Citizen.objects.all()
})
def citizen(request, citizen_id):
try:
citizen = Citizen.objects.get(sID=citizen_id)
except Citizen.DoesNotExist:
raise Http404("Citizen not found")
return render(request, "citizens/citizen.html", {
"citizen": citizen,
})
urls.py inside myproject
"""htql2 URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.2/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('admin/', admin.site.urls),
path('citizens/', include('citizens.urls')),
path('accounts/', include('django.contrib.auth.urls')),
path('users/', include('users.urls')),
]
urls.py inside users
from django.urls import path
from . import views
urlpatterns = [
path("", views.index, name="index"),
path("login", views.login_view, name="login"),
path("logout", views.logout_view, name="logout"),
]
views.py inside users
from django.views.decorators.csrf import csrf_exempt
from django.contrib.auth import authenticate, login, logout
from django.shortcuts import render
from django.http import HttpResponseBadRequest, HttpResponseRedirect, Http404
from django.urls import reverse
#csrf_exempt
# Create your views here.
def index(request):
if not request.user.is_authenticated:
return HttpResponseRedirect(reverse("login"))
return render(request, "users/user.html")
def login_view(request):
if request.method == "POST":
username = request.POST["username"]
password = request.POST["password"]
user = authenticate(request, username=username, password=password)
if user is not None:
login(request, user)
return HttpResponseRedirect(reverse("index"))
else:
return render(request, "users/login.html", {
"message": "Invalid credentials."
})
else:
return render(request, "users/login.html")
def logout_view(request):
pass
Inside user.html, I have tried to use
Go to Database
but doesn't work.
Thank you. I'm so grateful.
You have tried to use {% url 'citizen:citizens/' %} here the part before : (citizen) is a url namespace and the part after it (citizens) is the url name. But you haven't used any namespace, and neither do you have a url name as citizens.
You can add a namespace in citizens.urls by specifying app_name:
from django.urls import path
from . import views
app_name = 'citizens' # here
urlpatterns = [
path("", views.index, name="index"),
path("<int:citizen_id>", views.citizen, name="citizen"),
#path("<int:citizen_id>/passports", views.passport, name="passports")
]
Next you need to write the url tag as {% url 'citizens:index' %}:
Go to Database

Unable to call Django function for inserting data in postgres db

I am running the below code however when i submit create.html template it goes directly to home.html without inserting any record in postgres db. I believe, the function "create" is not called at all. Kindly assist
I tried directing the function
* views.py *
from django.shortcuts import render, redirect
from django.contrib.auth.decorators import login_required
from .models import Product
def home(request):
return render(request, 'products/home.html')
#login_required
def create(request):
if request.method =='POST':
product = Product()
product.title = request.POST['title']
product.save()
return redirect('home')
else:
return render(request, 'products/create.html')
* urls.py *
from django.urls import path,include
from . import views
urlpatterns = [
path('create',views.create,name='create'),]
* models.py *
from django.db import models
from django.contrib.auth.models import User
class Product(models.Model):
title = models.CharField(max_length=255)
def __str__(self):
return self.title
* apps.py *
from django.apps import AppConfig
class ProductsConfig(AppConfig):
name = 'products'
* Main url.py *
from django.contrib import admin
from django.urls import path,include
from products import views
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.home, name='home'),
path('products/', include('products.urls')),]
* urls.py *
from django.urls import path,include
from . import views
urlpatterns = [
path('create',views.create,name='create'),]
* create.html *
{%extends 'base.html'%}
{%block content%}
<form method="POST" action="{% url 'create' %}" enctype = "multipart/form-data">
{% csrf_token %}
Title:
<br/>
<input type="text" name = "title"/>
<br/><br/>
<input type="submit" class = "btn btn-primary" value = "Add Product"/>
</form>
{%endblock%}
I was expecting the record to be inserted in database (postgres) and I should be able to validate it using "django administration" page.
I am able to add the record manually via "django administration" page but not via above html form

getting error as "TypeError at /add_follow/1/ __init__() takes 1 positional argument but 2 were given"

urls.py
"""stratinum URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/1.10/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.conf.urls import url, include
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import url, include
from django.contrib import admin
from imagec import views as imagec_views
from contact import views as contact_views
from django.conf.urls.static import static
from django.conf import settings
from django.core.urlresolvers import reverse
admin.autodiscover()
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^$', imagec_views.home, name='home'),
url(r'^about/$', imagec_views.about, name='about'),
url(r'^detail/$', imagec_views.detail, name='detail'),
url(r'^profile/$', imagec_views.userProfile, name='profile'),
url(r'^create_form/$', imagec_views.create_form, name='create_form'),
url(r'^contact/$', contact_views.contact, name='contact'),
url(r'^userProfile/$', contact_views.contact, name='userProfile'),
url(r'^accounts/', include('allauth.urls')),
url('', include('social.apps.django_app.urls', namespace='social')),
url('', include('django.contrib.auth.urls', namespace='auth')),
url(r'^$', imagec_views.ListaFollow, name="lista_follow"),
url(r'^add_follow/(?P<id>\d{1,})/$', imagec_views.AddFollow, name='add_follow'),
url(r'^remove_follow/(?P<id>\d{1,})/$', imagec_views.RemoveFollow, name='remove_follow')
]
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
views.py
from django.contrib.auth.decorators import login_required
from django.shortcuts import render
from django.conf import settings
from django.core.files.storage import FileSystemStorage
from django.core.urlresolvers import reverse
from django.shortcuts import render, get_object_or_404
from .forms import AlbumForm
from .models import Album
from django.http import HttpResponse,HttpResponseForbidden
IMAGE_FILE_TYPES = ['png', 'jpg', 'jpeg']
# Create your views here.
def home(request):
context = {}
template = 'home.html'
return render(request, template, context)
def about(request):
context = {}
template = 'about.html'
return render(request, template, context)
#login_required()
def userProfile(request):
user = request.user
context = {'user': user}
template = 'profile.html'
return render(request, template, context)
def create_form(request):
form = AlbumForm(request.POST or None, request.FILES or None)
if form.is_valid():
album = form.save(commit=False)
album.user = request.user
album.image= request.FILES['image']
file_type = album.image.url.split('.')[-1]
file_type = file_type.lower()
if file_type not in IMAGE_FILE_TYPES:
context = {
'album': album,
'form': form,
'error_message': 'Image file must be PNG, JPG, or JPEG',
}
return render(request, 'detail.html', context)
album.save()
return render(request, 'create_form.html', {'album': album})
context = {
"form": form,
}
return render(request, 'create_form.html', context)
def detail(request):
user = request.user
#album = get_object_or_404(Album, pk=id)
return render(request, 'detail.html', {'user': user})
from django.shortcuts import render, redirect
from .models import Album
from django.views.generic import TemplateView,View
from django.db.models import Q
from django.core.urlresolvers import reverse
from . import models
#from imagec.models import User
from django.contrib.auth.models import Permission, User
class ListaFollow(TemplateView):
template_name = 'lista_follow.html'
def get_context_data(self,**kwargs):
context = super(ListaFollow,self).get_context_data(**kwargs)
context['all'] = Album.objects.all()
context['me'] = User.objects.get(user=self.request.user)
context['notme'] = Album.objects.filter(follow__user=self.request.user)
context['notfollow'] = Album.objects.filter(~Q(follow__user=self.request.user))
return context
class AddFollow(View):
def get(self,request, id):
me=models.Album.objects.get(user=request.user)
followed = models.Album.objects.get(id=id) #el wey
me.follow.add(followed)
return redirect(reverse('imagec/about.html'))
class RemoveFollow(View):
def get(self,request, id):
me=models.Album.objects.get(user=request.user) #instancia del usuario con el id que quiero crear
followed = models.Album.objects.get(id=id)
me.follow.remove(followed) #creo el usuario con mi nombre y la relacion
return redirect(reverse('imagec/about.html'))
models.py
from __future__ import unicode_literals
from django.contrib.auth.models import Permission, User
from django.db import models
# Create your models here.
class profile(models.Model):
name = models.CharField(max_length=120)
description = models.TextField(default='description default text')
def __unicode__(self):
return self.name
class Album(models.Model):
user = models.ForeignKey(User, default=1)
image = models.FileField()
follow = models.ManyToManyField('self', blank=True)
def __unicode__(self):
return self.user
about.html
{% extends 'base.html' %}
{% block content %}
<body>
<div class="container">
<h1>Profile</h1>
<p>Username: {{ user }}</p>
<p>Email: {{ user.email }}</p>
<p><input type="submit" value="Upload"/></p>
</div>
<table>
<tr>
<th colspan="3"> # {{ user }}</th>
</tr>
<tr>
<td colspan="3">
<span> Follows </span>
</td>
</tr>
<td>{{follow}} <a href="/add_follow/{{user.id}}">
<button>Follow</button></a></td>
<td>{{follow}} <a href="/remove_follow/{{user.id}}">
<button>Unfollow</button></a></td>
<tr>
<td colspan="3">
<span> Unfollows </span>
</td>
</tr>
</table>
</body>
{% endblock %}
I m getting as "TypeError at /add_follow/1/
__init__() takes 1 positional argument but 2 were given when on click on follow or unfollow button can any one give solution for this
It's hard to know what's wrong from the exception message alone. But when you are using class based views, you must call the as_view() function to use them in your url router.
https://docs.djangoproject.com/en/1.11/topics/class-based-views/#subclassing-generic-views
So change all the cbv routes (but not function views) in your urls.py
# BAD
url(r'^$', imagec_views.ListaFollow, name="lista_follow"),
# CORRECT
url(r'^$', imagec_views.ListaFollow.as_view(), name="lista_follow"),

form field not showing (django 1.7)

The form field (text area) is not showing in my django template. I can figure out where the problem is.
Views.py
class Profile(View):
"""User Profile page reachable from /user/<username> URL"""
def get(self, request, username):
params = dict()
user = User.objects.get(username=username)
tweets = Tweet.objects.filter(user=user)
params["tweets"] = tweets
params["user"] = user
return render(request, 'profile.html', params)
class PostTweet(View):
"""Tweet Post form available on page /user/<username> URL"""
def post(self, request, username):
if request.method == 'GET':
form = TweettForm()
else:
form = TweetForm(self.request.POST)
if form.is_valid():
user = User.objects.get(username=username)
tweet = Tweet(text=form.cleaned_data['text'], user=user, country=form.cleaned_data['country'])
tweet.save()
words = form.cleaned_data['text'].split(" ")
for word in words:
if word[0] == "#":
hashtag, created = HashTag.objects.get_or_create(name=word[1:])
hashtag.tweet.add(tweet)
return HttpResponseRedirect('/user/'+username)
return render(request, 'profile.html', {'form': form})
forms.py
from django import forms
class TweetForm(forms.Form):
text = forms.CharField(widget=forms.Textarea(attrs={'rows': 1, 'cols':85}), max_length=160)
country = forms.CharField(widget=forms.HiddenInput())
profile.html
{% extends "base.html" %}
{% block content %}
<div class="row clearfix">
<div class="col-md-12 column">
<form method="post" action="post/">{% csrf_token %}
<div class="col-md-8 col-md-offset-2 fieldWrapper">
{{ form.text.errors }}
{{ form.text }}
</div>
{{ form.country.as_hidden }}
<div>
<input type="submit" value="post">
</div>
</form>
</div>
urls.py
from django.conf.urls import patterns, include, url
from django.contrib import admin
from tweets.views import Index, Profile, PostTweet
admin.autodiscover()
urlpatterns = patterns('',
url(r'^$', Index.as_view()),
url(r'^user/(\w+)/$', Profile.as_view()),
url(r'^admin/', include(admin.site.urls)),
url(r'^user/(\w+)/post/$', PostTweet.as_view())
)
Only the submit (post) button shows on the on when rendered in the browser. The text are is not there
You get nothing since you are not passing the form to the template. Write get function in PostTweet view and include form = TweetForm() in it as a param passed to the template.