Closed sarahsaturday closed 1 year ago
settings.py
INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'rest_framework', 'rest_framework.authtoken', 'corsheaders', 'repairsapi', ]
REST_FRAMEWORK = { 'DEFAULT_AUTHENTICATION_CLASSES': ( 'rest_framework.authentication.TokenAuthentication', ), 'DEFAULT_PERMISSION_CLASSES': [ 'rest_framework.permissions.IsAuthenticated', ], }
CORS_ORIGIN_WHITELIST = ( 'http://localhost:3000', 'http://127.0.0.1:3000' )
MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'corsheaders.middleware.CorsMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', ]
Task: Set Up Django Project -- see comments for example from course work
[x] Create project and start virtual environment -- run this line by line: cd ~/workspace mkdir honey-rae-server cd honey-rae-server touch seed_database.sh touch db.sqlite3 pipenv shell
[x] Install Django and third party packages: pipenv install django autopep8 pylint djangorestframework django-cors-headers pylint-django
[x] Create Django project. Run django-admin startproject projectname . where projectname is the name of your project. Don't forget the dot!
[x] Add Pylint file -- run: **echo '[FORMAT] good-names=i,j,ex,pk
[MESSAGES CONTROL] disable=broad-except,imported-auth-user,missing-class-docstring,no-self-use,abstract-method
[MASTER] disable=C0114 ' > .pylintrc**
projectname-
"python.linting.pylintArgs": [ "--load-plugins=pylint_django", "--django-settings-module=honeyrae.settings", ],
*curl -L -s 'https://raw.githubusercontent.com/github/gitignore/master/Python.gitignore' > .gitignore echo '.sqlite3' >> .gitignore**
mkdir projectnameapi/models projectnameapi/views touch projectnameapi/models/init.py projectnameapi/views/init.py
[x] Edit the settings.py file -- See comments: there are four sections of your project's settings.py module. Replace your existing sections with the code below. These settings changes will be needed for any REST API application that you make. The only thing that will differ between applications is the name of the application itself. Below, you can see "repairsapi" in the list of installed apps. Whatever project you create in the future, your application names in that project will go there instead.
[x] Install any additional packages you may need for your project using pip. For example, you may need Django REST framework: pip install djangorestframework.
[x] Run initial migrations to create necessary database tables: python manage.py migrate.
[ ] (optional) Create a superuser account to access the Django admin interface (useful for managing data during development): python manage.py createsuperuser.
[ ] Option 1: Start the Django development server: python manage.py runserver You should see the server running locally.
[x] Option 2: Run the Django Server with VS Code Debugger: Inside the .vscode create a file called launch.json. Paste the following code in that file.
launch.json
{ "version": "0.2.0", "configurations": [ { "name": "Python: Django", "type": "python", "request": "launch", "program": "${workspaceFolder}/manage.py", "args": ["runserver"], "django": true, "autoReload":{ "enable": true } } ] }