Django Rest Attachment
Django Free Attachment is a Django app to provide a simple attachment service independent of any other model.
Detailed documentation is in the "docs" directory.
Quick start
- Setup environment
mkdir django
cd django
python -m venv .venv
source .venv/bin/activate
# Create requirements.txt file
cat <<EOF > requirements.txt
django<3,>=2.2
setuptools
djangorestframework
EOF
pip install -r requirements.txt
- Start Project
django-admin startproject proj
- Add "attachment" to your INSTALLED_APPS setting like this::
INSTALLED_APPS = [
...
'rest_framework',
'attachment',
]
- Add Media settings, if you have done this, ignore this step
MEDIA_DIR = os.path.join(BASE_DIR, "media")
MEDIA_ROOT = MEDIA_DIR
MEDIA_URL = '/media/'
- add routers.py to pro folder (the save folder with urls.py)
# routers.py
from rest_framework import routers
from attachment.viewsets import AttachmentViewSet
router = routers.SimpleRouter()
router.register(r'attachment', AttachmentViewSet, basename='attachment')
- Include the attachment and api URLconf in your project urls.py like this::
from django.urls import path, include
from django.conf.urls.static import static
from django.conf import settings
from .routers import router
urlpatterns = [
....
path('api/', include(router.urls), name='api'),
path('attachment/', include('attachment.urls'), name='attachment'),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
-
Run
python manage.py migrateto create the polls models. -
Add superuser
python manage.py createsuperuser
python manage.py runserver
- Start the development server and visit http://127.0.0.1:8000/admin/
Test
-
Visit http://127.0.0.1:8000/admin/attachment/ to upload a attachment from admin
-
Using Postman to post a REST request:
-
add
X-CSRFTokento header -
add
sessionid to Postman Cookies
Postman can automatically extract session from chrome browser refer Postman Doc
Release files for django-rest-attachment 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| django-rest-attachment-0.2.1.tar.gz | 410.9 kB | Details |
Release files / django-rest-attachment-0.2.1.tar.gz
| Download URL | django-rest-attachment-0.2.1.tar.gz |
|---|---|
| Size | 410.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6d9c48f8d9e8d9b64e14f05b5158a855f02f13fa091f3da142abfa99994cedf9
|
|
BLAKE2b-256 checksum How to use checksums |
21d63b85e9a4dc4e5131a6978173cc859be8c2a299a701e4b0f25c4120ca46fa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.2
|