Open vigneshs-dev opened 2 months ago
Hi there,
When you clone this application, there would be the frontend backend part, you need to spin up the server for each of these separately, for the Django app you need run the "pip install -r requirements.txt" and to run the server you need to run "python manage.py runserver" and for the react you need to install the packages also by running "yarn" after which you'll spin up the server by running "yarn dev"
After this your two applications should be connected and you can now visit localhost:3000 on your browser.
Let me know if you have any more questions
On Tue, Aug 20, 2024, 20:10 Vignesh S @.***> wrote:
Hi @desphixs https://github.com/desphixs , I have been following your Blog app tutorial using Django + React. I have completed almost 19 videos on that playlist. I am able to make API and Backend work perfectly. But the frontend React part is little complex for me as I am not aware of that totally. Can you please make steps to run this code locally in our system by just cloning this repository ?
— Reply to this email directly, view it on GitHub https://github.com/desphixs/Django-and-React-Blog/issues/1, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQPNAU7OUAHCFMQAWL6AQBTZSOIDBAVCNFSM6AAAAABM2QX4R6VHI2DSMVQWIX3LMV43ASLTON2WKOZSGQ3TMMZVGM3TOOI . You are receiving this because you were mentioned.Message ID: @.***>
Hi @desphixs ,
1 -> git clone https://github.com/desphixs/Django-and-React-Blog.git
2 -> cd Django-and-React-Blog
Backend
1 -> cd backend
2 -> python -m venv venv
3 -> venv/Scripts/activate
4 -> pip install -r requirements.txt
5 -> py manage.py runserver
-> Error -> ModuleNotFoundError: No module named 'environs'
-> To solve -> pip install environs
-> Error -> environs.EnvError: Environment variable "SITE_URL" not set
-> I don't know how to solve the last error.
In video tutorial, you have mentioned creating Superuser in Django, making migrations, migrate, etc., But in the steps you have mentioned nothing about that. Can you please full steps to run your Django + React Blog program to run locally in local system?
Frontend
1 -> npm install yarn --global
2 -> npm install vite --global
3 -> npm create vite@latest . -- --template react
-> Selected -> Ignore files and continue
4 -> yarn
5 -> yarn dev
After this step, I am able to run the frontend server. In that server, there is sample page running. Because App.jsx having the sample code only.
As I already told you, I have completed the Django part earlier. So, I made some changes in the App.jsx file and make the Django code which I have followed from your videos and made it run in the background, I am able to get almost 80 percent of the Blog webpage you have created. The main problem I faced during the time is, My Blog webpage is left aligned. I am not able to make it centre aligned.
Can you please provide steps to solve these probelms? Please provide clear steps to run your Blog code without editing any changes to the code which I have cloned from the GitHub.
After doing some research, I commented out the env variables in settings.py file in backend folder. After that also I come through multiple errors.
?: (staticfiles.W004) The directory 'C:\Users\Vignesh\Vicky\AWS-SAM\Blog\Django-and-React-Blog\backend\static' in the STATICFILES_DIRS setting does not exist.
Please provide detailed steps to run your full code locally.
Hi again, here is the step by step guide in detail
Clone the repository:
git clone [<repository-url>](https://github.com/desphixs/Django-and-React-Blog.git)
Navigate into the project directory:
cd path/to/project from your command prompt
Navigate to the backend
directory:
cd backend
Create and activate a virtual environment:
python -m venv venv
venv\Scripts\activate
source venv/bin/activate
Install Django dependencies:
pip install -r requirements.txt
Apply database migrations:
python manage.py migrate
Create a superuser (if necessary):
python manage.py createsuperuser
Run the Django development server:
python manage.py runserver
This will start the Django server on http://127.0.0.1:8000/
by default.
Navigate to the frontend
directory:
cd ../frontend
Install Node.js dependencies:
npm install or yarn (This will install libraries needed to run the react project)
Run the React development server:
npm run dev or yarn dev
This will start the React server on http://localhost:5173/
(if using Vite) or http://localhost:3000/
(if using Create React App).
If your frontend and backend are running on different ports (which is typical), you'll need to handle CORS.
Install django-cors-headers
:
pip install django-cors-headers
Update settings.py
in Django:
Add 'corsheaders'
to INSTALLED_APPS
:
INSTALLED_APPS = [
...,
'corsheaders',
]
Add CorsMiddleware
to the top of MIDDLEWARE
:
MIDDLEWARE = [
'corsheaders.middleware.CorsMiddleware',
...,
]
Set CORS_ALLOWED_ORIGINS
to include your frontend's URL:
CORS_ALLOWED_ORIGINS = [
"http://localhost:5173", # Or http://localhost:3000 for CRA
]
http://localhost:8000/
to check if the Django API is running.http://localhost:5173/
(or http://localhost:3000/
for CRA) to check if the React frontend is running.If you get any error, please paste the error message so I can take a look at it
If you get any error, please paste the error message so I can take a look at it
Thanks. Will check once and get you back.
Hi @desphixs ,
On the step - 4, I encounter the below error:
ModuleNotFoundError: No module named 'environs'
I solved that error using the below command:
pip install environs
After that, I continue from that step and received another error:
environs.EnvError: Environment variable "SITE_URL" not set
I don't know how to solve this error? Please guide me to solve this error.
I am able to run the frontend part without any problem till now.
Could you please run the implementation steps once in your system. From that you can get my problems on implementing your code. Really wonderful blog project. But I am not able to run that in my local system.
Set urls like this. SITE_URL = env.str("SITE_URL", default="http://localhost:8000") Run if you encounter any error to do with storages pip install django-storages
Hi @ vigneshs-dev Or set like this url SITE_URL=env("SITE_URL", default="http://localhost:8000") At least one should work on your environment
Hi @desphixs , I have been following your Blog app tutorial using Django + React. I have completed almost 19 videos on that playlist. I am able to make API and Backend work perfectly. But the frontend React part is little complex for me as I am not aware of that totally. Can you please make steps to run this code locally in our system by just cloning this repository ?