Posts

Showing posts from May, 2016

AttributeError: Got AttributeError when attempting to get a value for field `abc` on serializer `PfleSerializer`. The serializer field might be named incorrectly and not match any attribute or key on the `QuerySet` instance. Original exception text was: 'QuerySet' object has no attribute 'abc'.

AttributeError: Got AttributeError when attempting to get a value for field `abc` on serializer ` PfleSerializer `. The serializer field might be named incorrectly and not match any attribute or key on the `QuerySet` instance. Original exception text was: 'QuerySet' object has no attribute 'abc'. >>> p=Pfle.objects.all() >>> seri=PfleSerializer(p,many=True) >>> seri.data

How to rename folder using command prompt

mv oldfolder/ newfolder/

How to use SSH for webfaction

Linux systems, you can start and SSH session with the command line program ssh . At the command line, enter $ ssh username @ server_name .webfaction.com   and press Enter

show databases and tables in MySQL

mysql> show databases; +--------------------+ | Database           | +--------------------+ | information_schema | | django_db          | | mysql              | | performance_schema | | sys                | | test               | +--------------------+ 6 rows in set (0.52 sec) mysql> use test; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> show tables; +----------------------------+ | Tables_in_test             | +----------------------------+ | auth_group                 | | auth_group_permissions     | | auth_permission            | | auth_user                  | | auth_user_groups           | | auth_user_user_permissions | | django_admin_log           | | django_content_type        | | django_migrations          | | django_session             | | emp_details                | | employee_profile           | +----------------------------+ 12 rows in set (0.00 sec) mysql&

How to set settings.py for MySQL in django

use the password you entered when installing MySql $ mysql -u root -p Enter password: Welcome to the MySQL monitor.  Commands end with ; or \g. Your MySQL connection id is 8 Server version: 5.7.12-0ubuntu1 (Ubuntu) Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> CREATE DATABASE test; Query OK, 1 row affected (0.01 sec) mysql> show databases; +--------------------+ | Database           | +--------------------+ | information_schema | | django_db          | | mysql              | | performance_schema | | sys                | | test               | +--------------------+ 6 rows in set (0.52 sec) mysql> quit Bye Django database settings Edit settings.py: DATABASES = {     'default': {         'ENGIN

Error: That port is already in use.

$ (raghuvirtualenv)sanu@sanu-Inspiron-N5010:~/raghu/emp/empl$ python manage.py runserver Performing system checks... System check identified no issues (0 silenced). May 09, 2016 - 11:12:08 Django version 1.9.5, using settings 'empl.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CONTROL-C. Error: That port is already in use. $ (raghuvirtualenv)sanu@sanu-Inspiron-N5010:~/raghu/emp/empl$   Solution    $ (raghuvirtualenv)sanu@sanu-Inspiron-N5010:~/raghu/emp/empl$ ps aux | grep -i manage root       106  0.0  0.0      0     0 ?        S<   May08   0:00 [charger_manager] root       855  0.0  0.0  38328  2344 ?        Ss   May08   0:00 /sbin/cgmanager -m name=systemd root       862  0.0  0.1 337484  4948 ?        Ssl  May08   0:07 /usr/sbin/ModemManager root       899  0.0  0.2 449416  8272 ?        Ssl  May08   0:01 /usr/sbin/NetworkManager --no-daemon nobody    2259  0.0  0.0  52868  2712 ?        S    May08   0:00 /usr/sbin/dnsmasq --no-

How install httpie and send POST request through terminal

$ pip install httpie $ http -f POST http://127.0.0.1:8000/login/ imei=123 mac=987

Use Python Lists as Stacks

Image
>>> stack =[] >>> stack.append(1) >>> stack.append(2) >>> stack.append(2) >>> stack [1, 2, 2] >>> stack.append(3) >>> stack [1, 2, 2, 3] >>> stack.pop() 3 >>> stack.pop() 2 >>> stack [1, 2] >>>

Python List and Method

Create empty list : >>> list = [] 1) Add an item to the end of the list >>> list.append(1) 2) Extend the list by appending all the items in the given list >>>list1[1,2,3,4,5] >>>list.extend(list1) 3) Insert an item at a given position. The first argument is the index of the element before which to insert. >>>list.insert(0,3) 4) Remove the first item from the list whose value is 4. It is an error if there is no such item. >>>list.remove(4) 5) Remove the item at the given position in the list, and return it. If no index is specified, list.pop() removes and returns the last item in the list. >>>list.pop(1) 6) Return the index in the list of the first item whose value is x. >>> list.index(3) 7) Return the number of times x appears in the list. >>> list.count(3) 8) Sort the items of the list. >>>list.sort() 9) Reverse the elements of the list >>