Skip to content

Commit

Permalink
Merge pull request #56 from PeiPeiC/Readme-trouble-shooting
Browse files Browse the repository at this point in the history
Readme and fix minor bugs
  • Loading branch information
LixingwanCao authored Mar 14, 2024
2 parents c4cf75c + e7ec756 commit 0e8c667
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 8 deletions.
123 changes: 118 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,126 @@ This command generates a list of all installed packages in the active virtual en
📢 **Reminder for Collaborators**: Always run `pip install -r requirements.txt` after pulling changes from the repository to ensure your local environment matches the project's dependencies.
### Local Testing with Google Cloud API
For local testing, especially when integrating with Google Cloud API, use [ngrok](https://ngrok.com/) to expose your local server to a public URL.
# Fixing ImportError in Django App Development
```bash
ngrok http 8000
When developing a Django application, you might encounter the following error:
```
ImportError: cannot import name 'AppConf' from 'appconf' (D:\Work\SecondSavings\venv\Lib\site-packages\appconf\__init__.py)
```
This error typically occurs due to a conflict or an outdated package in your virtual environment. To resolve this issue, follow the steps below to delete your old virtual environment and set up a new one.
## Prerequisites
- Ensure you have Python and pip installed on your system.
- You should have virtualenv installed. If not, install it using pip:
```
pip install virtualenv
```
## Steps to Fix ImportError
1. **Navigate to Your Project Directory**
Open a terminal or command prompt and navigate to your Django project directory:
```
cd path/to/your/django/project
```
2. **Delete the Old Virtual Environment**
Before deleting your old virtual environment, ensure you deactivate it if it's currently active. To deactivate, simply run:
```
deactivate
```
Then, delete the virtual environment folder. On Windows, you can use:
```
rmdir /s /q venv
```
On macOS/Linux, use:
```
rm -rf venv
```
3. **Create a New Virtual Environment**
With the old environment removed, create a new virtual environment by running:
```
virtualenv venv
```
Replace `venv` with your preferred name for the virtual environment.
4. **Activate the New Virtual Environment**
- On Windows:
```
venv\Scripts\activate
```
- On macOS/Linux:
```
source venv/bin/activate
```
5. **Reinstall Dependencies**
Reinstall your project's dependencies including Django and any other packages you need. It's best to have a `requirements.txt` file; if you do, install using:
```
pip install -r requirements.txt
```
6. **Verify the Fix**
After setting up the new environment and reinstalling your dependencies, try running your Django application again. The ImportError should be resolved.
## Configuring Environment Variables
For enhanced security and to maintain the integrity of sensitive information, it is crucial to use an environment variables file, commonly named `.env`. This file will store confidential data such as secret keys and passwords, which should not be hard-coded into your Django project's settings or repositories, especially if they are public.
### Creating and Using the .env File
1. **Create a .env File**: In your project's root directory, create a file named `.env`. This file will not be tracked by version control if you include `.env` in your `.gitignore` file.
2. **Add Sensitive Data**: Open your `.env` file with a text editor and input your sensitive keys and credentials. Use the format `KEY=VALUE` without spaces around the equals sign. Based on the provided information, your `.env` file should include:
```
DJANGO_SECRET_KEY=your_django_secret_key_here
EMAIL_HOST_PASSWORD=your_email_host_password_here
EMAIL_HOST_USER=your_email_host_user_here
GOOGLE_CLIENT_ID=your_google_client_id_here
GOOGLE_CLIENT_SECRET=your_google_client_secret_here
REDIRECT_URI=http://127.0.0.1:8000/oauth2callback
```
Replace the placeholder values (`your_*_here`) with your actual credentials.
3. **Integrating .env Variables into Your Django Project**: To use these environment variables within your Django project, you'll need a package like `django-environ` to parse the `.env` file. Install it using pip:
```
pip install django-environ
```
Then, in your `settings.py` file, import and initialize `environ`:
```python
import environ
env = environ.Env()
# Reading .env file
environ.Env.read_env()
# Using the variables from .env
SECRET_KEY = env('DJANGO_SECRET_KEY')
EMAIL_HOST_PASSWORD = env('EMAIL_HOST_PASSWORD')
EMAIL_HOST_USER = env('EMAIL_HOST_USER')
GOOGLE_CLIENT_ID = env('GOOGLE_CLIENT_ID')
GOOGLE_CLIENT_SECRET = env('GOOGLE_CLIENT_SECRET')
REDIRECT_URI = env('REDIRECT_URI')
```

### Security Reminder

Never share your `.env` file or disclose its contents publicly. Ensure it is included in your `.gitignore` file to prevent accidental upload to version control systems.


This will provide a URL that can be used to test interactions with Google Cloud APIs.

Binary file modified requirements.txt
Binary file not shown.
2 changes: 1 addition & 1 deletion templates/TimeTracker/Group.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<form id="create-group-form">
<input type="text" id="group-name" class="form-control" placeholder="Group Name" required="width: 100% ">
<button type="button" id="search-button" class="btn btn-secondary" style="margin-bottom: 5px">Search Group</butston>
<button type="button" id="search-button" class="btn btn-secondary" style="margin-bottom: 5px">Search Group</button>
<button type="button" id="create-group-button"class="btn btn-secondary" style="margin-bottom: 5px">Create Group</button>
<button type="button" id="reset-button"class="btn btn-secondary" style="margin-bottom: 5px">Reset</button>
</form>
Expand Down
4 changes: 2 additions & 2 deletions templates/TimeTracker/setting.html
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ <h4>Synchronization</h4>
alert("Settings updated.");
}
},
error: function(response){
alert("Error updating settings.");
{% comment %} error: function(response){
alert("Error updating settings."); {% endcomment %}
}
});
});
Expand Down

0 comments on commit 0e8c667

Please sign in to comment.