-
Notifications
You must be signed in to change notification settings - Fork 0
/
python
61 lines (37 loc) · 1.45 KB
/
python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#Creating a virtual environment
-- pip install virtualenv
-- python -m venv env
OR
-- python3 -m venv env
#Activate an environment
-- source env/bin/activate
#To deactivate an environment
-- deactivate
#Creating a project
-- pipenv install django djangorestframework django-rest-knox
-- django-admin startproject leadmanager
-- python manage.py startapp leads
-- Go into leadmanager folder > vim settings > add leads + rest_frameworks under installed apps
-- cd ..
-- python manage.py makemigrations leads
-- python manage.py migrate (add everything to the database/create the tables)
#Creating a python serializer
-- cd leads
#Django Issue
-- There might be some issue with respect to disallowed hosts
-- Go to project settings.py
-- add requisite IP e.g. 10.150.50.10 into the allowedHost section
ALSO
-- run the ./manage.py runserver 0.0.0.0:8000
#using regular expressions and raw strings
raw strings are strings that don't pay attention to attributes such as new lines or tabs
e.g.
print("new line \n") == This will create a new line automatically
BUT
print(r"new lin\n") == The r converts the string into a raw string meaning, python will neglect the new tab directive
#PRINT without .format
print(f'this is a sample test {variable_to_be_inserted} ...'')
#using the requests method
-- the 'wb' is meant for 'writing bytes'
-- to get connents of a webpage in bytes, use the 'content' attribute
-- r.text - this returns the contents of a website in UNICODE