Twitter clone, implemented with Django and Django REST Framework.
Framework: Django
API: Django Rest Framework
Authentication: Google Authentication
Database: SQLite
Background Tasks Queue: Celery
Tasks Scheduler: Celery Beat
Message Broker: RabbitMQ
pip install -r requirements.txt
python manage.py makemigrations
python manage.py migrate
3. Open a new terminal, make sure your .venv (if using one) is active and run the below command to start the server
python manage.py runserver
5. Swagger docs available at: Link
-
Public endpoints - accessible without authentication
- Register user
- Login
-
Authentication Endpoints - require login with email and password
-
Features, related to users:
- Edit profile information (names and description only)
- Upload or change profile picture
- Retrieve user's posts and accumulated likes of all user's posts
- Logout
-
Features, related to posts:
- Submit a post
- Retrieve all posts (shows last 20 posts by default)
- Like/unlike a post
- Delete a post (owner required)
-
To test the authentication flow, run the server and directly access http://127.0.0.1:8000/google-oauth2/login/redirect/
in your browser. This is the link to the endpoint which will redirect the user to the Google login screen. It cannot be accessed directly through Swagger due to CORS.
On the Google login page, you may be asked to enter your Google credentials (email and password). Once logged in, you might see a consent screen asking you to allow DjangoTweet to access your profile information. Click Continue
to proceed.
After successful authorization, Google will redirect you back to DjangoTweet. This redirect includes an authorization code and a state parameter that helps ensure the security of the process.
Copy the token from the JSON body of the response and proceed to Try it out section for further instructions.
To activate background tasks, follow these steps:
Follow the official instructions for installation (Windows): Link
Ensure RabbitMQ is running. You can start RabbitMQ with:
.\rabbitmq-service.bat start
In one terminal window, start the Celery worker:
celery -A django_project worker -l info --pool=solo
In another terminal window, start Celery Beat:
celery -A django_project beat --loglevel=info
With these steps, the background tasks will be activated and your Celery worker along with Celery Beat will handle the scheduling and execution of tasks such as hard deleting posts that were marked as is_deleted
over a specified amount of time (can be changed in the posts/tasks.py
module).
The tasks are currently set to run every 30 seconds. You can change this in celery.py
.
authentication/ - google authentication logic
django_project/ - core project folder
├─ celery.py - celery settings
├─ serializers.py - model serializers
├─ settings.py - project settings
├─ urls.py - url patterns
media/ - media uploads
posts/ - posts app
├─ migrations/ - db migrations
├─ api.py - api logic
├─ admin.py - admin features
├─ core.py - core app module
├─ models.py - posts models
├─ services.py - crud logic
├─ tasks.py - background tasks
users/ - users app (structure similar to posts)
README.md - project decription
exceptions.py - custom exceptions
manage.py - main module
requirements.txt - project requirements
python manage.py createsuperuser
From the admin page, you can:
- see recently registered and sandboxed users
- mark users as active
- see deleted posts
- restore delete posts
- Click on Authorize button
- Example for Value field: Token 18ef4d413eb691df11c6f60719e3617fce1adb4a