Final Build:

static files replacement:

  • at first, in /twittme-web
    • npm run build to create new static files ```bash [root@localhost twittme-web]# npm run build

twittme-web@0.1.0 build /root/SourceCode/Python/reactjs/Twittme/twittme-web react-scripts build

Creating an optimized production build… Compiled successfully.

File sizes after gzip:

43.59 KB (+3.51 KB) build/static/js/2.46f141e7.chunk.js 3.54 KB (+367 B) build/static/js/main.bee67ef9.chunk.js 762 B build/static/js/runtime~main.a8a9905a.js 556 B build/static/css/main.0b57e251.chunk.css

The project was built assuming it is hosted at the server root. You can control this with the homepage field in your package.json. For example, add this to build it for GitHub Pages:

“homepage” : “http://myname.github.io/myapp“,

The build folder is ready to be deployed. You may serve it with a static server:

npm install -g serve serve -s build

Find out more about deployment here:

https://bit.ly/CRA-deploy

  1. - delete directories /static/css and /static/js
  2. - copy and paste directories /twittme-web/build/static/css and /twittme-web/build/static/js into /static
  3. - make file names of /templates/react/css.html and /templates/react/js.html identical to new static files
  4. ![image.png](https://cdn.nlark.com/yuque/0/2020/png/1243266/1597708429722-91a60b62-6a21-4ab6-a10c-528e5539be22.png#align=left&display=inline&height=372&margin=%5Bobject%20Object%5D&name=image.png&originHeight=744&originWidth=1137&size=77190&status=done&style=none&width=568.5)<br />![image.png](https://cdn.nlark.com/yuque/0/2020/png/1243266/1597708496999-4ca74eb8-d3e2-44b3-8484-b7347c2d9487.png#align=left&display=inline&height=368&margin=%5Bobject%20Object%5D&name=image.png&originHeight=736&originWidth=1228&size=82483&status=done&style=none&width=614)<br />now we got those changes about profiles.
  5. - finally, remember to update with collectstatic
  6. ```bash
  7. [root@localhost Twittme]# python3 ./manage.py collectstatic
  8. You have requested to collect static files at the destination
  9. location as specified in your settings:
  10. /root/SourceCode/Python/reactjs/Twittme/static-root
  11. This will overwrite existing files!
  12. Are you sure you want to do this?
  13. Type 'yes' to continue, or 'no' to cancel: yes
  14. 8 static files copied to '/root/SourceCode/Python/reactjs/Twittme/static-root', 164 unmodified.

profile badge:

  • in /templates/profiles/detail.html
    • add div block with class “tweetme-2-profile-badge” ```html {% extends ‘base.html’ %}

{% block content %}

{% endblock content %}

  1. runserver and see a profile<br />![image.png](https://cdn.nlark.com/yuque/0/2020/png/1243266/1597720836749-7314cf04-1a00-44e5-bf5e-e052b4617fab.png#align=left&display=inline&height=442&margin=%5Bobject%20Object%5D&name=image.png&originHeight=885&originWidth=1218&size=42517&status=done&style=none&width=609)<br />so that the profile badge is imported successfully.
  2. <a name="IvQdM"></a>
  3. #### Navbar:
  4. We have to update our navbar to make some pages accessible not just by urls, but also clicking.
  5. - modify /templates/components/navbar.html
  6. - apply "nav-item" and "nav-link" to create buttons that apply links in /Twittme/urls.py
  7. ![image.png](https://cdn.nlark.com/yuque/0/2020/png/1243266/1597721651889-046c922a-3830-4cee-9c78-8518268a9d59.png#align=left&display=inline&height=155&margin=%5Bobject%20Object%5D&name=image.png&originHeight=310&originWidth=597&size=25609&status=done&style=none&width=298.5)
  8. - depends on login and logout, there should have different buttons
  9. ```html
  10. <nav class="navbar navbar-expand-lg navbar-dark bg-tweetme mb-4">
  11. <a class="navbar-brand" href="/">Twittme</a>
  12. <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
  13. <span class="navbar-toggler-icon"></span>
  14. </button>
  15. <!--
  16. <div class="collapse navbar-collapse d-none" id="navbarSupportedContent">
  17. <ul class="navbar-nav mr-auto d-none">
  18. <li class="nav-item active">
  19. <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
  20. </li>
  21. -->
  22. <!--new-->
  23. <div class="collapse navbar-collapse" id="navbarSupportedContent">
  24. <ul class="navbar-nav ml-auto">
  25. <li class="nav-item">
  26. <!--
  27. <a class="nav-link" href="#">Link</a>
  28. -->
  29. <!--new-->
  30. <a class="nav-link" href="/">Home <span class="sr-only">(current)</span></a>
  31. </li>
  32. <!--
  33. <li class="nav-item dropdown">
  34. <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  35. Dropdown
  36. </a>
  37. <div class="dropdown-menu" aria-labelledby="navbarDropdown">
  38. <a class="dropdown-item" href="#">Action</a>
  39. <a class="dropdown-item" href="#">Another action</a>
  40. <div class="dropdown-divider"></div>
  41. <a class="dropdown-item" href="#">Something else here</a>
  42. </div>
  43. -->
  44. <!--new-->
  45. {% if request.user.is_authenticated %}
  46. <li class="nav-item">
  47. <a class="nav-link" href="/logout">Logout</a>
  48. </li>
  49. <li class="nav-item">
  50. <!--
  51. <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
  52. -->
  53. <!--new-->
  54. <a class="nav-link" href="/profile/edit">Edit</a>
  55. </li>
  56. <!--new-->
  57. {% else %}
  58. <li class="nav-item">
  59. <a class="nav-link" href="/login">Login</a>
  60. </li>
  61. <li class="nav-item">
  62. <a class="nav-link" href="/register">Register</a>
  63. </li>
  64. {% endif %}
  65. </ul>
  66. <form class="form-inline my-2 my-lg-0 d-none">
  67. <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
  68. <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
  69. </form>
  70. </div>
  71. </nav>

runserver and see the navbar.
If you are not login, the navbar shows “Home” “Login” and “Register” buttons
image.png
If you have logged in, the navbar shows “Home” “Logout” and “Edit” buttons
image.png
also, all those buttons are functional.