{"id":21646157,"url":"https://github.com/akashdip2001/pytweet","last_synced_at":"2026-04-16T15:02:00.363Z","repository":{"id":262248559,"uuid":"886664610","full_name":"akashdip2001/pyTweet","owner":"akashdip2001","description":"python full stack project - Twitter","archived":false,"fork":false,"pushed_at":"2025-03-06T22:48:34.000Z","size":35319,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-19T21:42:54.309Z","etag":null,"topics":["django","django-application","django-project","fullstack","fullstack-development","python","pythonproject","twitter","twitter-clone","webapp"],"latest_commit_sha":null,"homepage":"https://py-tweet.vercel.app","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/akashdip2001.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-11T11:39:09.000Z","updated_at":"2024-12-21T13:48:14.000Z","dependencies_parsed_at":"2025-03-19T21:49:39.387Z","dependency_job_id":null,"html_url":"https://github.com/akashdip2001/pyTweet","commit_stats":null,"previous_names":["akashdip2001/pytweet"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/akashdip2001/pyTweet","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akashdip2001%2FpyTweet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akashdip2001%2FpyTweet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akashdip2001%2FpyTweet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akashdip2001%2FpyTweet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/akashdip2001","download_url":"https://codeload.github.com/akashdip2001/pyTweet/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akashdip2001%2FpyTweet/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31891038,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-16T11:36:10.202Z","status":"ssl_error","status_checked_at":"2026-04-16T11:36:09.652Z","response_time":69,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["django","django-application","django-project","fullstack","fullstack-development","python","pythonproject","twitter","twitter-clone","webapp"],"created_at":"2024-11-25T06:37:51.796Z","updated_at":"2026-04-16T15:02:00.331Z","avatar_url":"https://github.com/akashdip2001.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"```yaml\r\nPy Projects\r\n│\r\n│── Python Projects\r\n│── Django Projects\r\n│     │\r\n│     │── Twitter: (under Devlopment)\r\n│     └── ...\r\n└── ...    \r\n```\r\n\r\n| [notes](https://github.com/akashdip2001/ML-Machine-Learning/blob/main/py/README.md) | [Python Projects](https://github.com/akashdip2001/Python-Projects) | [Django Projects](https://github.com/akashdip2001/pyTweet) | [python-advance](https://github.com/akashdip2001/python-advance) |\r\n| --- | --- | --- | --- |\r\n\r\n\u003cimg src=\"img/01.png\"\u003e\r\n\r\n[docs](https://docs.chaicode.com/getting-started-with-django/)\r\n\r\n```python\r\npython -m venv .venv\r\n.venv\\Scripts\\activate\r\n\r\npip install django\r\npip freeze \u003e requirements.txt\r\npip install -r requirements.txt\r\npython.exe -m pip install --upgrade pip\r\n\r\ndjango-admin startproject \u003cProject Name: pyMedia\u003e\r\ncd pyMedia\r\n\r\npython manage.py runserver\r\n# remove the Red error\r\npython manage.py makemigrations\r\npython manage.py migrate\r\n```\r\n\r\n\u003cimg src=\"img/02.png\"\u003e\r\n\r\n```python\r\npython manage.py runserver\r\n```\r\n\r\n\u003cimg src=\"img/03.png\"\u003e\r\n\r\n### Create Superuser\r\n\r\n```python\r\npython manage.py createsuperuser\r\n# Username (leave blank to use 'akash'): akashdip2001\r\n# Email address: akashdip.art@gmail.com\r\n# Password:M@...\r\n# Password (again):M@...\r\npython manage.py runserver\r\n```\r\n\r\n\u003cimg src=\"img/04.png\"\u003e\r\n\u003cimg src=\"img/05.png\"\u003e\r\n\r\n```yaml\r\nC:\\Users\\akash\\Desktop\\Py Projects\\full stack\\01 img text post with Admin\\\r\n│\r\n├── .venv/                      # Your virtual environment directory\r\n│\r\n├── pyMedia/                    # Project root directory\r\n│   ├── manage.py               # Django's command-line utility for administrative tasks\r\n│   ├── pyMedia/                # Django project folder (contains settings)\r\n│   │   ├── __init__.py         # Indicates that this is a Python package\r\n│   │   ├── asgi.py             # ASGI configuration\r\n│   │   ├── settings.py         # Main settings/configuration file for the Django project\r\n│   │   ├── urls.py             # URL routing for the project\r\n│   │   ├── wsgi.py             # WSGI configuration\r\n│   │   └── __pycache__/        # Cached bytecode for Python files\r\n│   │\r\n│   ├── app_name/               # Example Django app folder (optional)\r\n│   │   ├── migrations/         # Database migrations for the app\r\n│   │   ├── __init__.py\r\n│   │   ├── admin.py            # Admin configuration\r\n│   │   ├── apps.py             # App configuration\r\n│   │   ├── models.py           # Database models\r\n│   │   ├── tests.py            # Tests for the app\r\n│   │   ├── views.py            # View functions\r\n│   │   └── __pycache__/\r\n│\r\n├── requirements.txt            # List of packages to install with pip\r\n└── db.sqlite3                   # Default SQLite database file (generated after migrations)\r\n```\r\n\r\n\u003cimg src=\"img/06.png\"\u003e\r\n\r\n```python\r\nimport os\r\n```\r\n\r\n[docs](https://docs.chaicode.com/django-models/#defining-a-model)\r\n\r\n```python\r\n# at last of all\r\nMEDIA_URL = '/media/'\r\nMEDIA_ROOT = os.path.join(BASE_DIR, 'media')\r\n\r\nSTATIC_URL = '/static/'\r\nSTATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]\r\n```\r\n\r\n\u003cimg src=\"img/07.png\"\u003e\r\n\u003cimg src=\"img/08.png\"\u003e\r\n\r\n```python\r\nfrom django.conf import settings\r\nfrom django.conf.urls.static import static\r\n\r\nurlpatterns = [\r\n    path('admin/', admin.site.urls),\r\n    #...\r\n    #...\r\n] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)\r\n```\r\n\r\n---\r\n\r\n# Project set ✅ Now Create a app 🛩️\r\n\r\n[docs](https://docs.chaicode.com/jinja-templates-app-in-django/#apps-in-django)\r\n\r\n```python\r\npython manage.py startapp \u003capp Name: pyTweet\u003e\r\n```\r\n\r\n###### create a urls.py file in this \u003capp name\u003e diractry.\r\n\r\n###### and go to views.py \u0026 create a view to test the application is Run. view -\u003e template -\u003e inject.\r\n\r\n#### app -\u003e views.py\r\n\r\n```python\r\nfrom django.contrib import render\r\n\r\ndef index(request):\r\n    return render(request, 'index.html')\r\n```\r\n\r\n#### app -\u003e urls.py\r\n\r\n```python\r\nfrom django.urls import path\r\nfrom . import views\r\n\r\nurlpatterns = [\r\n    path('', views.index, name='index'),\r\n]\r\n```\r\n\r\n#### main (project) -\u003e settings.py -\u003e ask main we create a new app\r\n\r\n```python\r\n# Application definition\r\n\r\nINSTALLED_APPS = [\r\n    #'django.contrib.admin',\r\n    #'django.contrib.auth',\r\n    #'django.contrib.contenttypes',\r\n    #'django.contrib.sessions',\r\n    #'django.contrib.messages',\r\n    #'django.contrib.staticfiles',\r\n    'pyTweet',\r\n]\r\n\r\nTEMPLATES = [\r\n    {\r\n        # 'BACKEND': 'django.template.backends.django.DjangoTemplates',\r\n        'DIRS': [os.path.join(BASE_DIR, 'templates')],\r\n        # 'APP_DIRS': True,\r\n        # 'OPTIONS': {\r\n        #     'context_processors': [\r\n        #         'django.template.context_processors.debug',\r\n        #         'django.template.context_processors.request',\r\n        #         'django.contrib.auth.context_processors.auth',\r\n        #         'django.contrib.messages.context_processors.messages',\r\n        #     ],\r\n        # },\r\n    },\r\n]\r\n```\r\n\r\n#### main (project) -\u003e urls.py -\u003e ask main we create a new app and take all urls from this place.\r\n\r\n```python\r\n#from django.contrib import admin\r\nfrom django.urls import path, include\r\n#\r\n\r\nurlpatterns = #[\r\n    #path('admin/', admin.site.urls),\r\n    path('tweet/', include('pyTweet.urls')),\r\n#] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)\r\n```\r\n\r\n##### Then we create a index.html file in templates dir in app dir (pyTweet).\r\n\r\n```yaml\r\npyTweet\r\n│\r\n├── templates\r\n│    │\r\n│    └── index.html\r\n```\r\n\r\n```html\r\n\u003c!DOCTYPE html\u003e\r\n\u003chtml lang=\"en\"\u003e\r\n  \u003chead\u003e\r\n    \u003cmeta charset=\"UTF-8\" /\u003e\r\n    \u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" /\u003e\r\n    \u003ctitle\u003eDocument\u003c/title\u003e\r\n    \u003cstyle\u003e\r\n      body {\r\n        background-color: #000;\r\n        color: #fff;\r\n      }\r\n    \u003c/style\u003e\r\n  \u003c/head\u003e\r\n  \u003cbody\u003e\r\n    Test Akashdip 2001\r\n  \u003c/body\u003e\r\n\u003c/html\u003e\r\n```\r\n\r\n## In one short.\r\n\r\nafter tweet (project/url.py) control pass to --\u003e Tweet app --\u003e app/url.py --\u003e then render the views, So go to app/views.py --\u003e Then we pass a view named \"index\".\r\n\r\n```python\r\npython manage.py runserver\r\n```\r\n\r\n\u003cimg src=\"img/09.png\"\u003e\r\n\u003cimg src=\"img/10.png\"\u003e\r\n\r\n\u003cimg src=\"https://github.com/akashdip2001/college-final-year-project/raw/main/img/colour_line.png\"\u003e\r\n\r\n\u003c!-- Layouts configured -\u003e create models/ forms -\u003e connect it with app. --\u003e\r\n\r\n### create a layout.html in templates dir. so that we use it in everywhere.\r\n\r\n```yaml\r\n.venu\r\npyMedia\r\n│\r\n├── templates\r\n│    │\r\n│    └── layout.html\r\n```\r\n\r\n```html\r\n{% load static %}\r\n\u003c!DOCTYPE html\u003e\r\n\u003chtml lang=\"en\"\u003e\r\n\u003chead\u003e\r\n    \u003cmeta charset=\"UTF-8\"\u003e\r\n    \u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"\u003e\r\n    \u003ctitle\u003e\r\n        {% block title %}\r\n        pyMedia \u003c!--if anyone can't app any Title, so it's the default --\u003e\r\n        {% endblock %}\r\n    \u003c/title\u003e\r\n\u003c/head\u003e\r\n\u003cbody\u003e\r\n    \u003cdiv class=\"container\"\u003e\r\n        {% block content %}\r\n        {% endblock %}\r\n\u003c/body\u003e\r\n\u003c/html\u003e\r\n```\r\n\r\n[Bootstrap docs](https://getbootstrap.com/docs/5.3/getting-started/introduction/)\r\n\r\n```html\r\n\u003c!DOCTYPE html\u003e\r\n\u003chtml lang=\"en\"\u003e\r\n  \u003chead\u003e\r\n    \u003c!-- \u003cmeta charset=\"UTF-8\"\u003e\r\n    \u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"\u003e --\u003e\r\n    \u003clink\r\n      href=\"https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css\"\r\n      rel=\"stylesheet\"\r\n      integrity=\"sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH\"\r\n      crossorigin=\"anonymous\"\r\n    /\u003e\r\n    \u003c!-- \u003ctitle\u003eDocument\u003c/title\u003e --\u003e\r\n  \u003c/head\u003e\r\n  \u003cbody\u003e\u003c/body\u003e\r\n\u003c/html\u003e\r\n```\r\n\r\n### Modify the app/ index.html\r\n\r\n#### python 1st search project level layout, if not there then fond the layout in your app --\u003e So, no need to give the complete patch, just \"layout.html\"\r\n\r\n```html\r\n{% extends \"layout.html\" %} {% block title %} pyTweet {% endblock %} {% block\r\ncontent %}\r\n\u003ch1\u003eWelcome to pyTweet Django project\u003c/h1\u003e\r\n{% endblock %}\r\n```\r\n\r\n\u003cimg src=\"img/11.png\"\u003e\r\n\r\n### templates.layout.html\r\n\r\n```html\r\n\u003cbody class=\"bg-dark\"\u003e\r\n  \u003c!-- \u003cdiv class=\"container\"\u003e\r\n        {% block content %}\r\n        {% endblock %} --\u003e\r\n\u003c/body\u003e\r\n```\r\n\r\n### app.index.html\r\n\r\n```html\r\n\u003ch1 class=\"text-center text-white mt-4\"\u003eWelcome to pyTweet\u003c/h1\u003e\r\n```\r\n\r\n\u003cimg src=\"img/12.png\"\u003e\r\n\r\n[copy Nav bar from Bootstrap](https://getbootstrap.com/docs/5.3/components/navbar/)\r\n\r\n#### Because of it's a common Nav bar, for all pages... So we add it on templates/ layout.html\r\n\r\n```html\r\n\u003c/head\u003e\r\n\u003cbody class=\"bg-dark\"\u003e\r\n    \u003c!-- Copy \u0026 Pest the Nav Bar --\u003e\r\n    \u003cdiv class=\"container\"\u003e\r\n```\r\n\r\n### No need Dark bg manually.\r\n\r\n\u003cimg src=\"img/13.png\"\u003e\r\n\u003cimg src=\"img/14.png\"\u003e\r\n\u003cimg src=\"img/15.png\"\u003e\r\n\r\n# Layout ✅\r\n\r\n\u003cimg src=\"https://github.com/akashdip2001/college-final-year-project/raw/main/img/colour_line.png\"\u003e\r\n\r\n# Create models\r\n\r\n### app (pyTweet) --\u003e models.py\r\n\r\n```python\r\nfrom django.db import models\r\nfrom django.contrib.auth.models import User # Import the User model to modify everything of user\r\n\r\n# Create your models here.\r\n\r\nclass Tweet(models.Model):\r\n    user = models.ForeignKey(User, on_delete=models.CASCADE)\r\n    text = models.TextField(max_length=240)\r\n    photo = models.ImageField(upload_to='photos', blank=True, null=True)\r\n    created_at = models.DateTimeField(auto_now_add=True)\r\n    updated_at = models.DateTimeField(auto_now=True)\r\n```\r\n\r\n# ⚠️ Error:\r\n\r\n\u003cimg src=\"img/16.png\"\u003e\r\n\r\nThe error indicates that Django cannot use the `ImageField` in your model because the required `Pillow` library (used for image processing) is not installed.\r\n\r\n### Solution\r\n\r\n0. Optional\r\n\r\n   ```powershell\r\n   pip freeze \u003e requirements.txt\r\n   ```\r\n\r\n   ```go\r\n   asgiref==3.8.1\r\n   Django==5.1.3\r\n   pillow==11.0.0\r\n   sqlparse==0.5.1\r\n   tzdata==2024.2\r\n   ```\r\n\r\n1. **Install Pillow**:\r\n   Activate your virtual environment (if it’s not already activated), and then install `Pillow` by running:\r\n\r\n   ```powershell\r\n   python -m pip install Pillow\r\n   ```\r\n\r\n2. **Verify Installation**:\r\n   After installing, you can verify that `Pillow` is installed by running:\r\n\r\n   ```powershell\r\n   python -m pip show Pillow\r\n   ```\r\n\r\n3. **Run Migrations Again** (if necessary):\r\n   Once `Pillow` is installed, re-run the migrations to ensure everything is set up properly:\r\n\r\n   ```powershell\r\n   python manage.py makemigrations\r\n   ```\r\n\r\n   ```powershell\r\n   python manage.py migrate\r\n   ```\r\n\r\n4. **Restart the Development Server**:\r\n   After completing these steps, restart the Django development server:\r\n\r\n   ```powershell\r\n   python manage.py runserver\r\n   ```\r\n\r\n## Then register this model in admin model.\r\n\r\n### app/ admin.py\r\n\r\n\u003cimg src=\"img/17.png\"\u003e\r\n\u003cimg src=\"img/18.png\"\u003e\r\n\r\n### Now create app/ **forms.py**\r\n\r\n\u003cimg src=\"https://github.com/akashdip2001/college-final-year-project/raw/main/img/colour_line.png\"\u003e\r\n\r\n## models ✅\r\n\r\n## forms ✅\r\n\r\n## register tweets in admin ✅\r\n\r\n## views ⬇️ - define funsanality\r\n\r\n### after that --\u003e works on **Jinja Templates**\r\n\r\n# in Views\r\n\r\n        index\r\n        tweet list\r\n        tweet create\r\n        tweet edit\r\n        tweet delete\r\n\r\n\u003cimg src=\"https://github.com/akashdip2001/college-final-year-project/raw/main/img/colour_line.png\"\u003e\r\n\r\n## Now create the Template of every view\r\n\r\n```yaml\r\napp/ templates\r\n        │\r\n        ├── #index.html\r\n        ├── tweet_list.html\r\n        ├── tweet_form.html\r\n        ├── tweet_confirm_delete.html\r\n        │\r\n```\r\n\r\n### edit those html and must add urls in app/ urls.py\r\n\r\n#### after complete ✅ tweet_list.html\r\n\r\n```html\r\n{% extends \"layout.html\" %} {% block title %} pyTweet {% endblock %} {% block\r\ncontent %}\r\n\u003ch1 class=\"text-center mt-4\"\u003eWelcome to pyTweet Django project\u003c/h1\u003e\r\n\r\n\u003ca href=\"{% url 'tweet_create' %}\" class=\"btn btn-primary\"\r\n  \u003eCreate a new tweet\u003c/a\r\n\u003e\r\n\u003cdiv class=\"container row gap-3\"\u003e\r\n  {% for tweet in tweets %}\r\n  \u003c!--# for-loop through the tweets from view,py -\u003e def tweet_list(request): tweets = --\u003e\r\n  \u003cdiv class=\"card mt-3\"\u003e\r\n    \u003cimg src=\"{{tweet.photo.url}}\" class=\"card-img-top\" alt=\"...\" /\u003e\r\n    \u003cdiv class=\"card-body\"\u003e\r\n      \u003cp class=\"card-title\"\u003e{{tweet.user.username}}\u003c/p\u003e\r\n      \u003ch3 class=\"card-text\"\u003e{{tweet.text}}\u003c/h3\u003e\r\n      \u003ca href=\"{% url 'tweet_edit' tweet.id %}\" class=\"btn btn-warning\"\u003eEdit\u003c/a\u003e\r\n      \u003ca href=\"{% url 'tweet_delete' tweet.id %}\" class=\"btn btn-danger\"\r\n        \u003eDelete\u003c/a\r\n      \u003e\r\n    \u003c/div\u003e\r\n  \u003c/div\u003e\r\n  {% endfor %}\r\n\u003c/div\u003e\r\n\r\n{% endblock %}\r\n```\r\n\r\n\u003cimg src=\"img/19.png\"\u003e\r\n \r\n##### Now add some css from Bootstrap.\r\n```html\r\n\u003ca href=\"{% url 'tweet_create' %}\" class=\"btn btn-primary mb-4\"\u003eCreate a new tweet\u003c/a\u003e\r\n\u003c!-- \u003cdiv class=\"container row gap-3\"\u003e\r\n    {% for tweet in tweets %} --\u003e\r\n    \u003cdiv class=\"card mt-3\" style=\"width: 28rem;\"\u003e\r\n```\r\n\u003cimg src=\"img/20.png\"\u003e\r\n\r\n#### update tweet_form.html --\u003e create post\r\n\r\n\u003cimg src=\"img/21.png\"\u003e\r\n\r\n[Watch Video](img/22.mkv)\r\n[Watch Video](img/23.mp4)\r\n\r\n---\r\n\r\n---\r\n\r\n\u003cimg src=\"https://github.com/akashdip2001/college-final-year-project/raw/main/img/colour_line.png\"\u003e\r\n\r\n# Security\r\n\r\n### Secure rutes\r\n\r\n### add Registration -\u003e Lig in\r\n\r\n1. [Block Post create]()\r\n\r\n## all files without Security\r\n\r\n#### app/ views.py\r\n\r\n```python\r\nfrom django.shortcuts import render\r\nfrom .models import Tweet\r\nfrom .forms import TweetForm #Recheck --\u003e app/ forms.py --\u003e class TweetForm(forms.ModelForm):\r\nfrom django.shortcuts import get_object_or_404, redirect # get_object_or_404 is used to get the object from the model or return 404 error\r\n\r\n# Create your views here.\r\n\r\ndef index(request):\r\n    return render(request, 'index.html')\r\n\r\ndef tweet_list(request):\r\n    tweets = Tweet.objects.all().order_by('-created_at') # Get all the tweets from the database and order by created_at\r\n    return render(request, 'tweet_list.html', {'tweets': tweets}) # Pass the tweets to the template\r\n\r\ndef tweet_create(request):\r\n    if request.method == 'POST': # Check if the request method is POST\r\n        form = TweetForm(request.POST, request.FILES) # Create a form with the request data\r\n        if form.is_valid(): # Check if the form is valid\r\n            tweet = form.save(commit=False) # Don't Save the form data to the database, just hold it in the variable\r\n            tweet.user = request.user # Set the user of the tweet to the current user\r\n            tweet.save() # Now Save the tweet to the database\r\n            return redirect('tweet_list') # Redirect to the tweet list page\r\n    else:\r\n        form = TweetForm() # Create a new form\r\n    return render(request, 'tweet_form.html', {'form': form}) # Pass the form to\r\n\r\ndef tweet_edit(request, tweet_id):\r\n    tweet = get_object_or_404(Tweet, pk=tweet_id, user = request.user) # Get the tweet object from the database, user = request.user --\u003e only login user can edit the tweet.\r\n    if request.method == 'POST':\r\n        form = TweetForm(request.POST, request.FILES, instance=tweet)\r\n        if form.is_valid():\r\n            tweet = form.save(commit=False)\r\n            tweet.user = request.user\r\n            tweet.save()\r\n            return redirect('tweet_list')\r\n    else:\r\n        form = TweetForm(instance=tweet) # Create a form with the tweet data, instance=tweet is used to populate the form with the tweet data\r\n    return render(request, 'tweet_form.html', {'form': form}) # Pass the form to\r\n\r\n\r\ndef tweet_delete(request, tweet_id):\r\n    tweet = get_object_or_404(Tweet, pk=tweet_id, user = request.user) # Get the tweet object from the database, user = request.user --\u003e only login user can delete the tweet.\r\n    if request.method == 'POST':\r\n        tweet.delete() # Delete the tweet\r\n        return redirect('tweet_list')\r\n    return render(request, 'tweet_confirm_delete.html', {'tweet': tweet}) # Pass the tweet to the template\r\n```\r\n\r\n### app/ urls.py\r\n\r\n```python\r\nfrom django.urls import path\r\nfrom . import views\r\n\r\nurlpatterns = [\r\n    path('', views.tweet_list, name='tweet_list'),\r\n    path('create/', views.tweet_create, name='tweet_create'),\r\n    path('\u003cint:tweet_id\u003e/edit/', views.tweet_edit, name='tweet_edit'),\r\n    path('\u003cint:tweet_id\u003e/delete/', views.tweet_delete, name='tweet_delete'),\r\n\r\n]\r\n```\r\n\r\n### forms.py\r\n\r\n```python\r\nfrom django import forms\r\nfrom .models import Tweet\r\n\r\nclass TweetForm(forms.ModelForm):\r\n    class Meta:\r\n        model = Tweet\r\n        fields = ['text', 'photo']\r\n```\r\n\r\n### tweet_list.html\r\n\r\n```html\r\n{% extends \"layout.html\" %} {% block title %} pyTweet {% endblock %} {% block\r\ncontent %}\r\n\u003ch1 class=\"text-center mt-4\"\u003eWelcome to pyTweet Django project\u003c/h1\u003e\r\n\r\n\u003ca href=\"{% url 'tweet_create' %}\" class=\"btn btn-primary mb-4\"\r\n  \u003eCreate a new tweet\u003c/a\r\n\u003e\r\n\u003cdiv class=\"container row gap-3\"\u003e\r\n  {% for tweet in tweets %}\r\n  \u003c!--# for-loop through the tweets from view,py -\u003e def tweet_list(request): tweets = --\u003e\r\n  \u003cdiv class=\"card mt-3\" style=\"width: 24rem;\"\u003e\r\n    \u003cimg src=\"{{tweet.photo.url}}\" class=\"card-img-top\" alt=\"...\" /\u003e\r\n    \u003cdiv class=\"card-body\"\u003e\r\n      \u003cp class=\"card-title\"\u003e{{tweet.user.username}}\u003c/p\u003e\r\n      \u003ch3 class=\"card-text\"\u003e{{tweet.text}}\u003c/h3\u003e\r\n      \u003ca href=\"{% url 'tweet_edit' tweet.id %}\" class=\"btn btn-warning\"\u003eEdit\u003c/a\u003e\r\n      \u003ca href=\"{% url 'tweet_delete' tweet.id %}\" class=\"btn btn-danger\"\r\n        \u003eDelete\u003c/a\r\n      \u003e\r\n    \u003c/div\u003e\r\n  \u003c/div\u003e\r\n  {% endfor %}\r\n\u003c/div\u003e\r\n\r\n{% endblock %}\r\n```\r\n\r\n### tweet_form.html\r\n\r\n```html\r\n{% extends \"layout.html\" %} {% block title %} pyTweet {% endblock %} {% block\r\ncontent %}\r\n\u003ch1 class=\"text-center mt-4\"\u003eWelcome to pyTweet Django project\u003c/h1\u003e\r\n\r\n\u003ch2 class=\"text-left\"\u003e\r\n  {% if form.instance.pk %} Edit {% else %} Create {% endif %}\r\n\u003c/h2\u003e\r\n\r\n\u003cform method=\"post\" enctype=\"multipart/form-data\" class=\"form\"\u003e\r\n  {% csrf_token %}\r\n  \u003c!-- #for views.py -\u003e def tweet_create(request): -\u003e if form.is_valid(): # Check if the form is valid --\u003e\r\n  {{ form.as_p }}\r\n  \u003cbutton type=\"submit\" class=\"btn btn-warning\"\u003eSubmit\u003c/button\u003e\r\n  \u003cbutton type=\"reset\" class=\"btn btn-danger\"\u003eReset\u003c/button\u003e\r\n  \u003c!-- \u003cbutton type=\"button\" class=\"btn btn-primary\" onclick=\"window.location.href='{% url 'tweet_list' %}'\"\u003eCancel\u003c/button\u003e --\u003e\r\n  \u003ca href=\"{% url 'tweet_list' %}\" class=\"btn btn-primary\"\u003eCancel\u003c/a\u003e\r\n\u003c/form\u003e\r\n{% endblock %}\r\n```\r\n\r\n### tweet_confirm_delete.html\r\n\r\n```html\r\n{% extends \"layout.html\" %} {% block title %} pyTweet {% endblock %} {% block\r\ncontent %}\r\n\u003ch2 class=\"text-center mt-4\"\u003eIf once Delete -\u003e Never come back\u003c/h2\u003e\r\n\u003ch1 class=\"text-center mt-4\" style=\"color: rgb(252, 58, 58);\"\u003e\r\n  are you sure to Delete ?\r\n\u003c/h1\u003e\r\n\r\n\u003c!--see the post preview to delete--\u003e\r\n\u003cdiv class=\"card mt-3 mx-auto\" style=\"width: 24rem;\"\u003e\r\n  {% if tweet.photo %}\r\n  \u003cimg src=\"{{ tweet.photo.url }}\" class=\"card-img-top\" alt=\"Tweet image\" /\u003e\r\n  {% endif %}\r\n  \u003cdiv class=\"card-body text-center\"\u003e\r\n    \u003cp class=\"card-title\"\u003e{{ tweet.user.username }}\u003c/p\u003e\r\n    \u003ch3 class=\"card-text\"\u003e{{ tweet.text }}\u003c/h3\u003e\r\n  \u003c/div\u003e\r\n\u003c/div\u003e\r\n\r\n\u003cform method=\"post\"\u003e\r\n  {% csrf_token %}\r\n  \u003cdiv class=\"text-center mt-4\"\u003e\r\n    \u003cbutton type=\"submit\" class=\"btn btn-danger\"\u003eDelete\u003c/button\u003e\r\n    \u003ca href=\"{% url 'tweet_list' %}\" class=\"btn btn-success\"\u003eCancel\u003c/a\u003e\r\n  \u003c/div\u003e\r\n\u003c/form\u003e\r\n\r\n{% endblock %}\r\n```\r\n\r\n---\r\n\r\n# Block Post create, edit \u0026 delete\r\n\r\n```python\r\n#from django.shortcuts import render\r\n#from .models import Tweet\r\n#from .forms import TweetForm\r\n#from django.shortcuts import get_object_or_404, redirect\r\nfrom django.contrib.auth.decorators import login_required\r\n\r\n# Create your views here.\r\n\r\n# def index(request):\r\n#     return render(request, 'index.html')\r\n\r\n# def tweet_list(request):\r\n\r\n@login_required\r\ndef tweet_create(request):\r\n\r\n@login_required\r\ndef tweet_edit(request, tweet_id):\r\n\r\n@login_required\r\ndef tweet_delete(request, tweet_id):\r\n```\r\n\r\n### After this you cant edit any post in incognito (Private)\r\n\r\n---\r\n\r\n# Create user registration using Django forms --\u003e app/ forms.py\r\n\r\n#### forms.py\r\n\r\n```python\r\n# from django import forms\r\n# from .models import Tweet\r\nfrom django.contrib.auth.forms import UserCreationForm\r\nfrom django.contrib.auth.models import User\r\n\r\n# class TweetForm(forms.ModelForm):\r\n#     class Meta:\r\n#         model = Tweet\r\n#         fields = ['text', 'photo']\r\n\r\nclass UserRegisterForm(UserCreationForm):\r\n    email = forms.EmailField()\r\n\r\n    class Meta:\r\n        model = User\r\n        fields = ('username', 'email', 'password1', 'password2')\r\n\r\n```\r\n\r\n### create a folder, for custom Login\r\n\r\n```yaml\r\n.venu\r\npyMedia\r\n│\r\n├── templates\r\n│    │\r\n│    ├── registration\r\n│    │    ├── register: html\r\n│    │    ├── login: html\r\n│    │    └── logged_out: html\r\n│    │\r\n│    └── #layout.html\r\n```\r\n\r\n### update views.py\r\n\r\n```python\r\n#from django.shortcuts import render\r\n#from .models import Tweet\r\nfrom .forms import TweetForm, UserRegistrationForm\r\n#from django.shortcuts import get_object_or_404, redirect\r\nfrom django.contrib.auth.decorators import login_required\r\nfrom django.contrib.auth import authenticate, login\r\n\r\n## create views to user registration and login\r\ndef register(request):\r\n    if request.method == 'POST':\r\n        form = UserRegistrationForm(request.POST)\r\n        if form.is_valid():\r\n            # form.save() # Save the user to the database\r\n            # return redirect('tweet_list') # Redirect to the tweet list page\r\n            # or\r\n            user = form.save(commit=False)\r\n            user.set_password(form.cleaned_data['password1'])\r\n            user.save()\r\n            login(request, user)\r\n            return redirect('tweet_list')\r\n    else:\r\n        form = UserRegistrationForm()\r\n\r\n    return render(request, 'registration/register.html', {'form': form})\r\n```\r\n\r\n### update urls.py\r\n\r\n```python\r\nfrom django.urls import path\r\nfrom . import views\r\n\r\nurlpatterns = [\r\n    #path('', views.tweet_list, name='tweet_list'),\r\n    #path('create/', views.tweet_create, name='tweet_create'),\r\n    #path('\u003cint:tweet_id\u003e/edit/', views.tweet_edit, name='tweet_edit'),\r\n    #path('\u003cint:tweet_id\u003e/delete/', views.tweet_delete, name='tweet_delete'),\r\n    path('register/', views.register, name='register'),\r\n\r\n]\r\n```\r\n\r\n\u003cimg src=\"img/24.png\"\u003e\r\n\u003cimg src=\"img/25.png\"\u003e\r\n\r\n### python can't find the Login pg.\r\n\r\n### we update it in project(pyMedia)/ settings.py\r\n\r\n```python\r\n# STATIC_URL = 'static/'\r\n\r\n# DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'\r\n\r\n# MEDIA_URL = '/media/'\r\n# MEDIA_ROOT = os.path.join(BASE_DIR, 'media')\r\n\r\n# STATIC_URL = '/static/'\r\n# STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]\r\n\r\nLOGIN_URL = '/accounts/login/'\r\nLOGIN_REDIRECT_URL = '/pyTweet/'\r\nLOGOUT_REDIRECT_URL = 'PYTweet/'\r\n```\r\n\r\n### project/ urls.py\r\n\r\n```python\r\n# from django.contrib import admin\r\n# from django.urls import path, include\r\n# from django.conf import settings\r\n# from django.conf.urls.static import static\r\nfrom django.contrib.auth import views as auth_views\r\n\r\n# urlpatterns = [\r\n    # path('admin/', admin.site.urls),\r\n    # path('pyTweet/', include('pyTweet.urls')),\r\n    path('accounts/', include('django.contrib.auth.urls')),\r\n\r\n# ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)\r\n```\r\n\r\n\u003cimg src=\"img/26.png\"\u003e\r\n\u003cimg src=\"img/27.png\"\u003e\r\n\r\n# ⚠️ Error in Register pg.\r\n\r\n### one user cant's edit other's post But see the edit button\r\n\r\n### Hide the edit button with condition\r\n\r\n#### tweet_liest.html\r\n\r\n```html\r\n\u003c!-- \u003cdiv class=\"container row gap-3\"\u003e\r\n    {% for tweet in tweets %}\r\n    \u003cdiv class=\"card mt-3\" style=\"width: 24rem;\"\u003e\r\n        \u003cimg src=\"{{tweet.photo.url}}\" class=\"card-img-top\" alt=\"...\"\u003e\r\n        \u003cdiv class=\"card-body\"\u003e\r\n            \u003cp class=\"card-title\"\u003e{{tweet.user.username}}\u003c/p\u003e\r\n            \u003ch3 class=\"card-text\"\u003e{{tweet.text}}\u003c/h3\u003e --\u003e\r\n{% if tweet.user == user %}\r\n\u003c!-- \u003ca href=\"{% url 'tweet_edit' tweet.id %}\" class=\"btn btn-warning\"\u003eEdit\u003c/a\u003e\r\n            \u003ca href=\"{% url 'tweet_delete' tweet.id %}\" class=\"btn btn-danger\"\u003eDelete\u003c/a\u003e --\u003e\r\n{% endif %}\r\n\u003c!-- \u003c/div\u003e\r\n    \u003c/div\u003e\r\n    {% endfor %}\r\n\u003c/div\u003e --\u003e\r\n```\r\n\r\n##### Registration pg not work -\u003e this user 2 created by admin\r\n\r\n\u003cimg src=\"img/31.png\"\u003e\r\n\r\n# Logout\r\n\r\n\u003cimg src=\"img/28.png\"\u003e\r\n\u003cimg src=\"img/29.png\"\u003e\r\n\r\n### you have to a Registered user , otherwise you can't see the Logout Button\r\n\r\n\u003cimg src=\"img/30.png\"\u003e\r\n\r\n# ⚠️ Logout Button not work\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakashdip2001%2Fpytweet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fakashdip2001%2Fpytweet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakashdip2001%2Fpytweet/lists"}