Last active
June 23, 2024 05:59
-
-
Save rg3915/d6a59f375c10a4fc0e9520b5dc0e0ff6 to your computer and use it in GitHub Desktop.
fix app Django
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Fix new app | |
DIR=$(pwd) | |
APP_NAME=$1 | |
# Add route on urls.py | |
sed -i "\@path('admin@ s@.*@ path('$APP_NAME/', include('backend.$APP_NAME.urls', namespace='$APP_NAME')),\n&@" $DIR/backend/urls.py | |
# Insert text in INSTALLED_APPS | |
sed -i "s/\]\s*$/ 'backend.$APP_NAME',\n]/" $DIR/backend/settings.py | |
# Insert text before app name on apps.py | |
sed -i "s/^ *name *= *'$APP_NAME' *$/ name = 'backend.$APP_NAME'/" $DIR/backend/$APP_NAME/apps.py | |
# Create app/urls.py | |
cat << EOF > $DIR/backend/$APP_NAME/urls.py | |
from django.urls import path | |
from backend.$APP_NAME import views as v | |
app_name = '$APP_NAME' | |
urlpatterns = [ | |
path('', v.person_list, name='person_list'), # noqa E501 | |
path('create/', v.person_create, name='person_create'), # noqa E501 | |
path('<int:pk>/', v.person_detail, name='person_detail'), # noqa E501 | |
path('<int:pk>/update/', v.person_update, name='person_update'), # noqa E501 | |
] | |
EOF | |
cat << EOF | |
Update files: | |
/backend/urls.py | |
/backend/settings.py | |
/backend/$APP_NAME/apps.py | |
/backend/$APP_NAME/urls.py | |
EOF | |
batcat backend/urls.py | |
batcat backend/settings.py -r 36:52 | |
batcat backend/$APP_NAME/apps.py | |
batcat backend/$APP_NAME/urls.py |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment