These are chat archives for django/django

3rd
Sep 2018
Shashank Parekh
@sp1rs
Sep 03 2018 06:03
@ryan-WORK Please elaborate.
megri
@megri
Sep 03 2018 09:20
Hello. I have a problem with reverse migrations, where the reverse errors out with LookupError: No installed app with label 'my_app'.. The particular migration has dependencies on three other projects: it is these projects that it can't find when doing the reverse. The forward migration works without issues.
I am running Django 2.1.1
Replace "projects" with "django apps"
tecoLai
@tecoLai
Sep 03 2018 09:36

Hi, I am a beginner of django. Have one question about virtualenv
When I fellow the tutorial of django.
It said that we can use this command to create virtual env
python3 -m venv venvName

And then I figure out that if we install virtualenv, it also can help us to create virtual env.
What isthe different between the way that django provided and virtualenv?

It should answer your question
matrixbot
@matrixbot
Sep 03 2018 13:06
Georgios Mavropalias Hello! Here in line 44, I need to make this for loop show the number of votes in a poll choice and display them in the progress bar, how would I do that ? Thank you ! https://github.com/TheDemocracyFoundation/epitome/blob/development/Demoscopesis/templates/Demoscopesis/poll.html
Arvind Venkatesh
@Arvindsinc2
Sep 03 2018 14:07

import os
import sys
import os.path

from django.core.wsgi import get_wsgi_application

from django.contrib.sites.shortcuts import get_current_site
request = None
full_url = ''.join(['http://', get_current_site(request).domain, obj.get_absolute_url()])

if full_url == "http://x.network":
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(file),'comingsoon')))
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "comingsoon.settings")
application = get_wsgi_application()

elif full_url == "http://y.tech":
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(file),'comingsoon2')))
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "comingsoon2.settings")
application = get_wsgi_application()

I am getting error with this
Frank Godo
@frankintrahouse
Sep 03 2018 14:13
What is the error you are getting?
matfire
@matfire
Sep 03 2018 15:50
Hello everyone, I am trying to build a react/DRF website and I am trying to use session authentication. When I try to POST the login data to the auth view, I get the error that the CSRF token is not set. I tried to set it manually(with axios's defaults according to an answer I found on StackOverflow) and even to force it on the view with a decorator. Nothing. Can you guys help me?
Shashank Parekh
@sp1rs
Sep 03 2018 15:54
@matfire Paste the code.
matfire
@matfire
Sep 03 2018 15:55

sure.

import { Form, Icon, Input, Button, Checkbox } from 'antd';

const FormItem = Form.Item;

axios.defaults.xsrfCookieName = 'csrftoken'
axios.defaults.xsrfHeaderName = 'X-CSRFToken'

class NormalLoginForm extends React.Component {
  handleSubmit = (e) => {
    e.preventDefault();
    this.props.form.validateFields((err, values) => {
      if (!err) {
        console.log('Received values of form: ', values);
      }
      axios.post("http://localhost:8000/login/", values).then(res=>console.log(res));
    });
  }

  render() {
    const { getFieldDecorator } = this.props.form;
    return (
      <Form onSubmit={this.handleSubmit} className="login-form">
        <FormItem>
          {getFieldDecorator('username', {
            rules: [{ required: true, message: 'Please input your username!' }],
          })(
            <Input prefix={<Icon type="user" style={{ color: 'rgba(0,0,0,.25)' }} />} placeholder="Username" name="username" id="id_username"/>
          )}
        </FormItem>
        <FormItem>
          {getFieldDecorator('password', {
            rules: [{ required: true, message: 'Please input your Password!' }],
          })(
            <Input prefix={<Icon type="lock" style={{ color: 'rgba(0,0,0,.25)' }} />} type="password" placeholder="Password" name="password" id="id_password"/>
          )}
        </FormItem>
        <FormItem>
          <Button type="primary" htmlType="submit" className="login-form-button">
            Log in
          </Button>
          Or <a href="/register">register now!</a>
        </FormItem>
      </Form>
    );
  }
}

const Login = Form.create()(NormalLoginForm);

export default Login;

this is the react component

    path("login/", auth_views.LoginView.as_view()),
this is the url to login
Shashank Parekh
@sp1rs
Sep 03 2018 16:03
Your imported axios ?
matfire
@matfire
Sep 03 2018 16:04
yes
import axios from 'axios';
Shashank Parekh
@sp1rs
Sep 03 2018 16:06
Pass the csrf token with the submit request.
matfire
@matfire
Sep 03 2018 16:06
what do you mean?
matfire
@matfire
Sep 03 2018 16:09
I had read that, and I think I did as he wrote, but still...
Shashank Parekh
@sp1rs
Sep 03 2018 16:11
Rendering the CSRF Token in React Forms look for this in the article.
matfire
@matfire
Sep 03 2018 16:19
still nothing... Tried to render the token in the form, but still getting 403 error
Shashank Parekh
@sp1rs
Sep 03 2018 16:19
Can you paste that code? python one also.
matfire
@matfire
Sep 03 2018 16:21
import React, {Component} from "react";
import {connect} from "react-redux";
import axios from 'axios';
import {Link} from "react-router-dom";
import CSRFToken from './csrf';



import { Form, Icon, Input, Button, Checkbox } from 'antd';

const FormItem = Form.Item;

axios.defaults.xsrfCookieName = 'csrftoken'
axios.defaults.xsrfHeaderName = 'X-CSRFToken'

class NormalLoginForm extends React.Component {
  handleSubmit = (e) => {
    e.preventDefault();
    this.props.form.validateFields((err, values) => {
      if (!err) {
        console.log('Received values of form: ', values);
      }
      axios.post("http://localhost:8000/login/", values).then(res=>console.log(res));
    });
  }

  render() {
    const { getFieldDecorator } = this.props.form;
    return (
      <Form onSubmit={this.handleSubmit} className="login-form" method="post" action="http://localhost:8000/login/">
      <CSRFToken />
        <FormItem>
          {getFieldDecorator('username', {
            rules: [{ required: true, message: 'Please input your username!' }],
          })(
            <Input prefix={<Icon type="user" style={{ color: 'rgba(0,0,0,.25)' }} />} placeholder="Username" name="username" id="id_username"/>
          )}
        </FormItem>
        <FormItem>
          {getFieldDecorator('password', {
            rules: [{ required: true, message: 'Please input your Password!' }],
          })(
            <Input prefix={<Icon type="lock" style={{ color: 'rgba(0,0,0,.25)' }} />} type="password" placeholder="Password" name="password" id="id_password"/>
          )}
        </FormItem>
        <FormItem>
          <Button type="primary" htmlType="submit" className="login-form-button">
            Log in
          </Button>
          Or <a href="/register">register now!</a>
        </FormItem>
      </Form>
    );
  }
}

const Login = Form.create()(NormalLoginForm);

export default Login;

React

Python

    path("login/", auth_views.LoginView.as_view()),

I am using the default django login view

zandar
@z4nD4R
Sep 03 2018 17:40
Hello Anyone here skilled and interrested to talk about the architecture of project?
Ryan
@ryan-WORK
Sep 03 2018 18:26

@sp1rs

Hey! Thanks for reaching out!

I implementation needs to be a custom view that will handle a POST request, and validate the data based on specific keys in the header rather than the response.data

do you know ho to do this?

or anyone?

Essentialy it could be looed at as validation of serializer in the views, maybe lol
matfire
@matfire
Sep 03 2018 18:49
I can now safely log in, but I don't seem to be able to retrieve the user performing the request. Even after the log is succesfull(status 200), the request.user is anonymous