49 cards
View
Draft

pycharm sources root

To make a source visible go into the settings and select project -> project structure then select the directory that contains the sources root.

https://www.jetbrains.com/help/pycharm/configuring-content-roots.html

Linked content

pycharm modules

Use the module option for the run configuration, see under "scrip path:module name"

See Also

drf jwt

https://simpleisbetterthancomplex.com/tutorial/2018/12/19/how-to-use-jwt-authentication-with-django-rest-framework.html

Linked contentDraft

django multiple databases

Step 1: Setup DB in settings

Step 2: Setup DB Routing

Step 3: Migration

Step 4: Testing

Reference

django CSRF Disable

Sample class for CSRF disable

from rest_framework.authentication import SessionAuthentication, BasicAuthentication

class CsrfExemptSessionAuthentication(SessionAuthentication):

    def enforce_csrf(self, request):
        return  # To not perform the csrf check previously happening

In view add

class MyTableDetailApiView(generics.RetrieveUpdateDestroyAPIView):
    queryset = MyTable.objects.all()
    serializer_class = MyTableSerializer
    authentication_classes = (CsrfExemptSessionAuthentication, BasicAuthentication)

Draft

vue delimiters in django

Sample delimiter replacement for django

<script>
new Vue({
  delimiters: ['[[', ']]'],
  el: '#app',
  data: {
    title: 'Welcome to My Journal'
  }
})
</script>

See Also

vuejs with django

Draft

django admin user

python manage.py createsuperuser
Draft

pycharm django project root

In setttings go
language & Frameworks
Django

Set djano project root
set default timeout

Draft

django admin reverse url lookup

Add form

Given app is called <app_name> and model in the app is called <model_table> then the following gets the link to the "add" form on the admin page:

url = reverse('admin:<app_name>_<model_table>_add')
Draft

Apache gunicorn

See Also

Draft

django rename app

Before renaming

Always migrate databases before changing the app name.

manage.py makemigrations

when you see the following message then it is safe to proceed with renaming the app.

No changes detected

Fixed table names

For this case it is assumed the table names are fixed in models.py

Rename and Loose migration

  1. remove migrations from db:
manage.py migrate --fake old_app_name zero
  1. remove migration files from app
find old_app_name -path "*/migrations/*.py" \
     -not -name "__init__.py" \
...
Draft

apache django mod_wsgi

install mod_wsgi.so

add to base.conf

nano /etc/httpd/conf.modules.d/00-base.conf

add this line

LoadModule wsgi_module modules/mod_wsgi.so
Draft

apache django setup

ctos-7

files

file | description
/etc/httpd/conf/httpd.conf | main config file
/etc/httpd/conf.d/ | config subdir
/etc/httpd/conf.modules.d/00-base.conf | enable wsgi_module

Instructions

Draft

django create app in subdir

To create a "polls" app in the "apps" sub-directory, do the following first to make the directory (assuming you are at the root of your django project):

mkdir apps/polls

Next, run startapp to create "polls" in under the "app" project directory.

startapp polls apps/polls

Install the app;

INSTALLED_APPS = [
'apps.polls'
]

migrate:

makemigrations polls
migrate

optional:
main urls.py

urlpatterns = [
path('polls/',include('apps.polls.urls'),
]

See Also

django migrate

Draft

django url parameters and view functions

url.py

url(r'^stores/',stores_views.detail,{'location':'headquarters'})

views.py

def detail(request,location=None):

Reference

url parameters

Draft

django migrate

basic

makemigration <app>
migrate

with python path

if an apps dir is used to organize the apps then do the following

makemigrations myapp --pythonpath apps
migrate

See also

django apps in subfolder

Draft

django foreign key self

Example

class CategoryModel(models.Model):
    parentId = models.ForeignKey('self')

References

This website uses short-lived cookies to improve usability.
Accept or learn more