These are chat archives for django/django

20th
Sep 2017
Renjith S Raj
@Cadmus
Sep 20 2017 08:48
there is any open source projects? i really intersted to contriburte
Luke-VideoLibre
@LukeVideo
Sep 20 2017 09:55
I'm having issues with a login view taht i adapted (copy pasted) from another project where it works fine. It might be obvious but i don't get it
here is the code
from django.shortcuts import render
from django.contrib.auth import authenticate, login, logout

from django.core.urlresolvers import reverse
from django.contrib.auth.decorators import login_required

from django.http import HttpResponseRedirect, HttpResponse
from django.views import generic
from django.shortcuts import redirect

from players.models import UserInfo
from players.forms import UserForm, UserInfoForm

#######

def user_login(request):
    if request.method == 'POST':
        username = request.POST.get('username')
        password = request.POST.get('password')

        user = authenticate(username=username, password=password)

        if user:
            if user.is_active:
                login(request, user)
                return HttpResponseRedirect(reverse('index'))
            else:
                return HttpResponse('account not active')
        else:
            return HttpResponse('invalid login or password')
    else:
        return render(request, 'players/login.html', {})
{% extends "players/base.html" %}

{% block main %}
  {% include "players/nav.html" %}
  <h1>Please login</h1>

  <form  action="{% url 'user_login' %}" method="post">
    {% csrf_token %}
    <label for="username">username :</label>
    <input type="text" name="username" placeholder="enter username">

    <label for="password">password :</label>
    <input type="password" name="password">

    <input type="submit" name="" value="Login">
  </form>

  {% endblock %}
app_name = "players"
urlpatterns = [
    url(r'^$', index, name='index'),
    url(r'^register/', register, name='register'),
    url(r'^user_login/$',user_login,name='user_login'),
    url(r'^user_logout/$',user_logout,name='user_logout'),

]
Luke-VideoLibre
@LukeVideo
Sep 20 2017 10:01
error is
NoReverseMatch at /players/user_login/

Reverse for 'user_login' not found. 'user_login' is not a valid view function or pattern name.

Request Method:     GET
Request URL:     http://127.0.0.1:8000/players/user_login/
Django Version:     1.11.5
Exception Type:     NoReverseMatch
Exception Value:     

Reverse for 'user_login' not found. 'user_login' is not a valid view function or pattern name.

Exception Location:     /home/XXXXXXXXXXXXXXlib64/python3.6/site-packages/django/urls/resolvers.py in _reverse_with_prefix, line 497
Python Executable:     /home/XXXXXXXXXXXXXX/bin/python
Python Version:     3.6.2
Python Path:     

['/home/XXXXXXXXXXXXXX/smartcluedo',
 '/usr/lib64/python36.zip',
 '/usr/lib64/python3.6',
 '/usr/lib64/python3.6/lib-dynload',
 '/homeXXXXXXXXX/lib64/python3.6/site-packages',
 '/homeXXXXXXXXXXXXXX/lib/python3.6/site-packages']

Server time:     Wed, 20 Sep 2017 10:01:50 +0000
Luke-VideoLibre
@LukeVideo
Sep 20 2017 10:16

ok got it :smile:

  <form  action="{% url 'user_login' %}" method="post">

should be :

  <form  action="{% url 'players:user_login' %}" method="post">

Forgot the name space there...

Luke-VideoLibre
@LukeVideo
Sep 20 2017 19:37

On another hand i got this error

'utf-8' codec can't decode byte 0xe8 in position 6: invalid continuation byte.

The thing is i am returning bytecode after encrypting a string. So my model had a textfield to enter the text to encrytpt. But my view return cypher Byte code... But if i put a byteField it can't be handled by the forms.py... So i have to find a solution to have a textfield on my page and pass a string to my view that passes it as byteCode to the model to save. Did anyone experience that or has advise on how to handle that ?