feat: rest framework hello world

This commit is contained in:
Tahinli 2024-06-28 00:56:50 +03:00
parent ed1d65fa62
commit 5dd685e882
7 changed files with 48 additions and 25 deletions

43
.idea/workspace.xml generated
View file

@ -1,20 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="AutoImportSettings">
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="b4bf3f98-d5b7-4d99-9ccf-5a322ed50222" name="Changes" comment=""> <list default="true" id="b4bf3f98-d5b7-4d99-9ccf-5a322ed50222" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/inspectionProfiles/profiles_settings.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/modules.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/tJango.iml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/manage.py" afterDir="false" />
<change afterPath="$PROJECT_DIR$/tJango/__init__.py" afterDir="false" />
<change afterPath="$PROJECT_DIR$/tJango/asgi.py" afterDir="false" />
<change afterPath="$PROJECT_DIR$/tJango/settings.py" afterDir="false" />
<change afterPath="$PROJECT_DIR$/tJango/urls.py" afterDir="false" />
<change afterPath="$PROJECT_DIR$/tJango/wsgi.py" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -45,17 +36,21 @@
<option name="hideEmptyMiddlePackages" value="true" /> <option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" /> <option name="showLibraryContents" value="true" />
</component> </component>
<component name="PropertiesComponent">{ <component name="PropertiesComponent"><![CDATA[{
&quot;keyToString&quot;: { "keyToString": {
&quot;ASKED_ADD_EXTERNAL_FILES&quot;: &quot;true&quot;, "ASKED_ADD_EXTERNAL_FILES": "true",
&quot;RunOnceActivity.OpenDjangoStructureViewOnStart&quot;: &quot;true&quot;, "RunOnceActivity.OpenDjangoStructureViewOnStart": "true",
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;, "RunOnceActivity.ShowReadmeOnStart": "true",
&quot;git-widget-placeholder&quot;: &quot;main&quot;, "git-widget-placeholder": "main",
&quot;nodejs_package_manager_path&quot;: &quot;npm&quot;, "node.js.detected.package.eslint": "true",
&quot;settings.editor.selected.configurable&quot;: &quot;com.jetbrains.python.configuration.PyActiveSdkModuleConfigurable&quot;, "node.js.detected.package.tslint": "true",
&quot;vue.rearranger.settings.migration&quot;: &quot;true&quot; "node.js.selected.package.eslint": "(autodetect)",
"node.js.selected.package.tslint": "(autodetect)",
"nodejs_package_manager_path": "npm",
"settings.editor.selected.configurable": "com.jetbrains.python.configuration.PyActiveSdkModuleConfigurable",
"vue.rearranger.settings.migration": "true"
} }
}</component> }]]></component>
<component name="RunManager"> <component name="RunManager">
<configuration name="tJango" type="Python.DjangoServer" factoryName="Django server"> <configuration name="tJango" type="Python.DjangoServer" factoryName="Django server">
<module name="tJango" /> <module name="tJango" />
@ -99,7 +94,7 @@
<option name="presentableId" value="Default" /> <option name="presentableId" value="Default" />
<updated>1719511805110</updated> <updated>1719511805110</updated>
<workItem from="1719511812328" duration="309000" /> <workItem from="1719511812328" duration="309000" />
<workItem from="1719512143097" duration="198000" /> <workItem from="1719512143097" duration="830000" />
</task> </task>
<servers /> <servers />
</component> </component>

5
.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,5 @@
{
"cSpell.words": [
"viewsets"
]
}

View file

@ -37,8 +37,15 @@ INSTALLED_APPS = [
'django.contrib.sessions', 'django.contrib.sessions',
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'rest_framework',
] ]
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
]
}
MIDDLEWARE = [ MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware', 'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware',

View file

@ -16,8 +16,24 @@ Including another URLconf
""" """
from django.contrib import admin from django.contrib import admin
from django.urls import path, include from django.urls import path, include
from django.contrib.auth.models import User
from rest_framework import routers, serializers, viewsets
class UserSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = User
fields = ['url', 'username', 'email', 'is_staff']
class UserViewSet(viewsets.ModelViewSet):
queryset = User.objects.all()
serializer_class = UserSerializer
router = routers.DefaultRouter()
router.register(r'users', UserViewSet)
urlpatterns = [ urlpatterns = [
path("", include("hello.urls")), path('api-auth/', include('rest_framework.urls')),
path('hello', include("hello.urls")),
path('', include(router.urls)),
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
] ]