Re: Is it possible to use REST API on Django template ?

2020-11-26 Thread Venu Gopal
Yes, it is possible. Below is the documentation. we will use serialization
to get a django rest API.
https://docs.djangoproject.com/en/3.1/topics/serialization/

On Wed, Nov 25, 2020 at 7:48 PM Aman Modi  wrote:

>
>
> Hello Django lovers.
>
> I want to use REST API  on Django template but i have no idea how can i do
> that.
> I want to use same API on android app and Django template.
>
> Any suggestion .
>
> Thanks and regard
> Aman Modi
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/99c6d921-9ea7-4f3b-9d69-03b06fbbd5d8n%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAOhYkiw-2jq%2B%3DLaxWZ8gZPsx0fsDLbKWivyZ2skJomj6oygu3Q%40mail.gmail.com.


Exception Type: TemplateSyntaxError at /login/ Exception Value: Invalid block tag on line 23: 'csrf_tocken', expected 'endblock'. Did you forget to register or load this tag?

2020-11-26 Thread The Dream Travelers
hi friends,

please help me to  resolve this issue..


Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/login/

Django Version: 3.1.3
Python Version: 3.9.0
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'log']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']


Template error:
In template C:\django-projects\dp1\site1\log\templates\log\login.html, 
error at line 23
   Invalid block tag on line 23: 'csrf_tocken', expected 'endblock'. Did 
you forget to register or load this tag?
   13 :
   14 :
   15 :
   16 : {% extends "log/base.html" %}
   17 : {% block content %}
   18 : Login page
   19 : 
   20 : 
   21 : 
   22 : 
   23 :  {% csrf_tocken %} 
   24 : 
   25 : 
   26 : 
   27 : 
   28 : 
   29 : 
   30 : 
   31 : 
   32 : 
   33 : 


Traceback (most recent call last):
  File "C:\django-projects\venv\lib\site-packages\django\template\base.py", 
line 470, in parse
compile_func = self.tags[command]

During handling of the above exception ('csrf_tocken'), another exception 
occurred:
  File 
"C:\django-projects\venv\lib\site-packages\django\core\handlers\exception.py", 
line 47, in inner
response = get_response(request)
  File 
"C:\django-projects\venv\lib\site-packages\django\core\handlers\base.py", 
line 179, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\django-projects\dp1\site1\log\views.py", line 20, in login_user
return render(request, 'log/login.html', {})
  File "C:\django-projects\venv\lib\site-packages\django\shortcuts.py", 
line 19, in render
content = loader.render_to_string(template_name, context, request, 
using=using)
  File 
"C:\django-projects\venv\lib\site-packages\django\template\loader.py", line 
61, in render_to_string
template = get_template(template_name, using=using)
  File 
"C:\django-projects\venv\lib\site-packages\django\template\loader.py", line 
15, in get_template
return engine.get_template(template_name)
  File 
"C:\django-projects\venv\lib\site-packages\django\template\backends\django.py", 
line 34, in get_template
return Template(self.engine.get_template(template_name), self)
  File 
"C:\django-projects\venv\lib\site-packages\django\template\engine.py", line 
143, in get_template
template, origin = self.find_template(template_name)
  File 
"C:\django-projects\venv\lib\site-packages\django\template\engine.py", line 
125, in find_template
template = loader.get_template(name, skip=skip)
  File 
"C:\django-projects\venv\lib\site-packages\django\template\loaders\base.py", 
line 29, in get_template
return Template(
  File "C:\django-projects\venv\lib\site-packages\django\template\base.py", 
line 155, in __init__
self.nodelist = self.compile_nodelist()
  File "C:\django-projects\venv\lib\site-packages\django\template\base.py", 
line 193, in compile_nodelist
return parser.parse()
  File "C:\django-projects\venv\lib\site-packages\django\template\base.py", 
line 478, in parse
raise self.error(token, e)
  File "C:\django-projects\venv\lib\site-packages\django\template\base.py", 
line 476, in parse
compiled_result = compile_func(self, token)
  File 
"C:\django-projects\venv\lib\site-packages\django\template\loader_tags.py", 
line 270, in do_extends
nodelist = parser.parse()
  File "C:\django-projects\venv\lib\site-packages\django\template\base.py", 
line 478, in parse
raise self.error(token, e)
  File "C:\django-projects\venv\lib\site-packages\django\template\base.py", 
line 476, in parse
compiled_result = compile_func(self, token)
  File 
"C:\django-projects\venv\lib\site-packages\django\template\loader_tags.py", 
line 213, in do_block
nodelist = parser.parse(('endblock',))
  File "C:\django-projects\venv\lib\site-packages\django\template\base.py", 
line 472, in parse
self.invalid_block_tag(token, command, parse_until)
  File "C:\django-projects\venv\lib\site-packages\django\template\base.py", 
line 522, in invalid_block_tag
raise self.error(

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on 

Unable to Login

2020-11-26 Thread vamshi eega
Hello , am new to Django and i created a login page ,but unable to get 
login , please help me to solve this , thank you in advance 





views.py : 
===

from django.views import *
from django.shortcuts import render, redirect
from django.http import HttpResponse
from django.contrib.auth import authenticate
from django.contrib.auth.models import User
from django.contrib.auth import authenticate, login

# Create your views here.
def signup(request):
if request.method == "POST":
if request.POST['password1'] == request.POST['password2']:
try:
User.objects.get(username=request.POST['username'])
return 
render(request,'accounts/signup.html',{'error':"Username already exist"})
except User.DoesNotExist:

user=User.objects.create_user(request.POST['username'],request.POST['password1'])
login(request,user)
return render(request,'accounts/signup.html',{'error':"user 
account created  Successfully "})
else:
return render(request,'accounts/signup.html',{'error':"password 
didnt match"})
else:
return render(request,'accounts/signup.html')

def loginview(request):
if request.method=="POST":
 username=request.POST['username']
 password=request.POST['password']
 user=authenticate(username=username,password=password)
 if user is not None:
 login(request,user)
 return render(request,'accounts/login.html',{"error":"Login 
successful!!"})
 else:
return render(request,'accounts/login.html',{"error":"username 
and password didnt match"})
else:
 return render(request,'accounts/login.html')


Note : when i enter login credentials , i unable to get message " Login 
successful" . please solve me on this  


urls.py :
=

from django.contrib import admin
from django.urls import path
import accounts.views
urlpatterns = [
path('admin/', admin.site.urls),
path('signup/', accounts.views.signup,name='signup'),
path('login/', accounts.views.loginview,name='login'),
]

login.html:
===

Login

{% if error %}
{{ error }}


{% endif %}


{% csrf_token %}
Username:



Password:









-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c68b3563-aaf2-4e99-b6a6-ca0002f4fbecn%40googlegroups.com.